0916作业
猜年龄游戏
age = 22 # 设定的年龄
age_count = 0
prize_dict ={
1:'下料一日游',
2:'机加工操作',
3:'焊接学习',
4:'装配实习'
}
while age_count < 3:
# 猜年龄游戏的代码主体
age_inp = input('请输入您猜测的年龄:')
if not age_inp.isdigit():
# 判断是否输入的是纯数字==》判断输入的不是纯数字就跳过。
print ('请您输入纯数字年龄')
continue
int_age_inp = int(age_inp)
if int_age_inp < age:
print('您猜小了')
elif int_age_inp > age:
print('您猜大了')
else:
print('恭喜您猜对了!')
print('下面进入奖品选择界面')
print(prize_dict)
prize_count = 0
while prize_count < 2:
choice_prize = input('请您选择想要礼品,并输入相应的序号:')
int_choice_prize = int(choice_prize)
for prize in prize_dict:
if prize == int_choice_prize:
print('恭喜您获得:',prize_dict[prize])
prize_count += 1
game_end=input('请输入‘Y’或‘y’退出游戏:')
if game_end == ('Y' or 'y'):
break
break
age_count += 1
print('游戏结束')