练习——循环2
作者:互联网
一、猜年龄
age = 18
x = 3
prize_dict ={
'1': '女朋友',
'2': 'ps4pro',
'3': 's9世界赛决赛门票',
'4': '霍格沃兹入学通知书',
'5': '哆啦A梦',
'6': '皮卡丘',
'7': '核弹发射按钮',
'8': '潘多拉魔盒',
'9': '死亡笔记',
'10': '幻想乡永久居住证'
}
while x > 0:
guess = input('猜猜我的年龄>>> ').strip()
if not guess.isdigit():
print('好好说个数字啦!')
continue
guess = int(guess)
if guess > age:
if x != 1:
x -= 1
print(f'猜大啦!你还有{x}次机会!')
while True:
answer = input('想继续玩吗?回复Y可以继续,回复N就直接退出啦!').lower()
if answer == 'y':
break
elif answer == 'n':
print('下次再来玩哦,再见啦!')
x = 0
break
else:
print('别乱回复鸭!')
print('输入Y或者N就行啦!')
continue
print('还是猜大啦!没机会咯!拜拜~~')
break
elif guess < age:
if x != 1:
x -= 1
print(f'猜小啦!你还有{x}次机会!')
while True:
answer = input('想继续玩吗?回复Y可以继续,回复N就直接退出啦!').lower()
if answer == 'y':
break
elif answer == 'n':
print('下次再来玩哦!再见啦!')
x = 0
break
else:
print('别乱回复鸭!')
print('输入Y或者N就行啦!')
continue
print('还是猜小啦!没机会咯!拜拜~')
break
else:
if x == 3:
print('好厉害啊,一次就猜对啦!')
elif x == 2:
print('恭喜你!猜对啦!')
else:
print('终于猜对啦!')
for i in range(2):
show = prize_dict.items()
for j in show:
print(j)
if i == 0:
choice_1 = input('选择一份奖品吧!不要的话也可以输入‘N’退出哦!').strip()
if choice_1 == 'N':
print('呜呜呜~~一件喜欢的都没有吗?')
break
if not choice_1 in prize_dict:
print('别乱输入鸭!')
print('输入奖品对应的数字就行啦!')
continue
prize1 = prize_dict[choice_1]
print(f'你的第一件奖品就是 {prize1} 啦!呐,请收好。')
prize_dict.pop(choice_1)
choice_2 = input('还能再选择一件哦,不想要了就输入‘N’吧。').strip()
if choice_2 == 'N':
print('拜拜~下次再来玩哦!')
break
if not choice_2 in prize_dict:
print('别乱输入鸭!')
print('输入奖品对应的数字就行啦!')
continue
prize2 = prize_dict[choice_2]
print(f'你的第二件奖品就是 {prize2} 啦,请收好哦')
break
print('游戏结束啦!下次再来玩吧!')
break
标签:guess,prize,练习,choice,break,循环,dict,print 来源: https://www.cnblogs.com/binyuanxiang/p/11515142.html