猜年龄游戏
'''
给定年龄,用户可以猜三次年龄年龄猜对,让用户选择两次奖励用户选择两次奖励后可以退出
'''
age=18
count=0
get_prize={}
prize={
'0':'布娃娃',
'1':'面包',
'2':'大米',
'3':'坦克',
'4':'水槽',
}
while count<3:
guess_age=input('请输入你的年龄:').strip()
guess_age=int(guess_age)
if guess_age>age:
print('猜大了')
elif guess_age<age:
print('猜小了')
else:
print('猜对了')
while count < 2:
print(prize)
choice= input('请选择你需要的奖品:').strip()
if not choice.isdigit():
print('请输入正确的数字:')
continue
if choice not in prize:
print('请重新输入:')
continue
prize_dict = prize[choice]
if prize_dict in get_prize:
get_prize[prize_dict] += 1
else:
get_prize[prize_dict] = 1
print(f'你得到的奖品是:{prize_dict}')
count += 1
print(f'你得到的总奖品是:{get_prize}')
break
count+=1