while (当) while条件快:
inp_age = input('请输入你的年龄: ')
inp_age = int(inp_age)
if inp_age < 18:
print('太小了')
elif inp_age == 18:
print('猜对了')
else:
print('太大了')
请输入你的年龄: 18
猜对了
while true:
inp_age = input('>>age: ')
inp_age = int(inp_age)
if inp_age < 18:
print('太小了')
elif inp_age == 18:
print('猜对了')
else:
print('太大了')
while true:
inp_age = input('>>age: ')
inp_age = int(inp_age)
if inp_age < 18:
print('太小了')
elif inp_age == 18:
print('猜对了')
break
else:
print('太大了')
3条命
life = 0
can_play_circle = 3
while life < can_play_circle:
inp_age = input('>>age: ')
inp_age = int(inp_age)
if inp_age <18:
print('太小了')
elif inp_age == 18:
print('猜对了')
break
else:
print('太大了')
life += 1
>>age: 15
太小了
>>age: 16
太小了
>>age: 11
太小了
life = 0
can_play_circle = 3
award_list = ['扭一扭','舔一舔','泡一泡']
while life < can_play_circle:
inp_age = input('>>age: ')
inp_age = int(inp_age)
if inp_age <18:
print('太小了')
elif inp_age == 18:
print(f'猜对了!!!
请挑选您的礼物:{award_list}')
if life == 1:
print('金牌')
elif life == 2:
print('银牌')
else:
print('铜牌')
break
else:
print('太大了')
life += 1
>>age: 15
太小了
>>age: 18
猜对了!!!
请挑选您的礼物:['扭一扭', '舔一舔', '泡一泡']
金牌
name = 'nick'
print(f'my name is {name}')
my name is nick
d = {1:'AA', 2:'BB', 3:'cc'}
print(d[2])
BB
life = 0
can_play_circle = 3
award_dict = {1:'AA', 2:'BB', 3:'cc'}
while life < can_play_circle:
inp_age = input('>>age:')
inp_age = int(inp_age)
if inp_age < 18:
print('太小了')
elif inp_age == 18:
print(f'恭喜你!!
请选择你的奖品序号:{award_dict}')
choice = input('请选择你的奖品序号: ')
choice = int(choice)
get_award = award_dict[choice]
print(f'恭喜你获得了奖品:{get_award}')
break
else:
print('太大了')
life += 1
>>age:15
太小了
>>age:22
太大了
>>age:18
恭喜你!!
请选择你的奖品序号:{1: 'AA', 2: 'BB', 3: 'cc'}
请选择你的奖品序号: 2
恭喜你获得了奖品:BB
a = 0
life = 0
can_play_circle = 3
award_dict = {1:'AA', 2:'BB', 3:'CC'}
while life < can_play_circle:
inp_age = input('>>>age: ')
inp_age = int(inp_age)
if inp_age < 18:
print('太小了')
elif inp_age == 18:
print(f'恭喜你!!!
请挑选你的礼物:{award_dict}')
while a < 2:
choice = input('请选择你的礼物编号: ')
choice = int(choice)
get_award = award_dict[choice]
print(f'恭喜你获得了礼物:{get_award}')
a += 1
break
else:
print('太大了')
life += 1
>>>age: 15
太小了
>>>age: 22
太大了
>>>age: 18
恭喜你!!!
请挑选你的礼物:{1: 'AA', 2: 'BB', 3: 'CC'}
请选择你的礼物编号: 1
恭喜你获得了礼物:AA
请选择你的礼物编号: 2
恭喜你获得了礼物:BB