作业
'''
1. 给定年龄,用户可以猜三次年龄
2. 年龄猜对,让用户选择两次奖励
3. 用户选择两次奖励后可以退出
'''
age_count = 0 # 计数
age = 18
while age_count < 3:
age_inp = input('请输入你猜的年龄:') # 与用户交互
if not age_inp.isdigit():
print('输入错误')
continue
age_inp_int = int(age_inp)
# 核心逻辑
if age_inp_int > age:
print('猜大了')
elif age_inp_int < age:
print('猜小了')
else:
print('猜对了')
# 奖品信息
award_dict = {
'0': '马云',
'1': '马化腾',
'2': '马冬梅',
}
print(award_dict)
choice_count = 0 # 计数
choice_dic = {}
while choice_count < 2:
# 与用户交互
choice = input('请输入奖品编号: ')
award = award_dict[choice]
print(f'你选择的奖品是: {award}')
# 保存用户选择信息
if award in choice_dic:
choice_dic[award_dict[choice]] += 1
else:
choice_dic[award_dict[choice]] = 1
print(f'已选奖品为: {choice_dic}')
choice_count += 1
print(f'你的奖品为: {choice_dic}')
break
age_count += 1