1.Python基础实战之猜年龄游戏
#项目实战 猜年龄游戏
count=0 #猜测次数
k=1 #获奖次数
m=0#输错次数
age=25
gift_list=['鸡腿','故事书','动画片']
print('欢迎来到猜年龄游戏,每人每轮有3次猜测次数机会,每轮猜对即可获得两次领取礼品哦,领取完可退出')
while count<4:
if count == 3:
again_inp = input('是否继续游戏,继续请输入"Y/y",否则任意键直接退出.')
if again_inp == 'Y'or again_inp == 'y':
count = 0
else:
break
else:
age_inp = input('输入你猜测年龄:')
age_inp_int = int(age_inp)
#漏了
if not age_inp.isdigit():
print('你的年龄输错了')
continue
if age_inp_int > age:
print('猜大了')
elif age_inp_int < age:
print('猜小了')
elif age_inp_int == age:
print(f'猜对了,可以领两次领礼品哦,按0礼物是{gift_list[0]},按1礼物是{gift_list[1]},按2礼物是{gift_list[2]}')
for i in range(4):
if k<3:
gift_inp = input('请输入你想要的奖品,如果不想要,则输入"N/n"退出!!!连续输错2次直接退出游戏')
if gift_inp =='n' or gift_inp =='N':
break
elif int(gift_inp) in [0,1,2]:
print(f'成功领取 {gift_list[int(gift_inp)]}')
k+=1
else:
print('请重新输入')
k=k
m+=1
if m==2:
break
# else:
# break
break
count += 1
2.Python进阶实战之三级菜单
menu = {
'北京': {
'海淀': {
'五道口': {
'soho': {},
'网易': {},
'google': {}
},
'中关村': {
'爱奇艺': {},
'汽车之家': {},
'youku': {},
},
'上地': {
'百度': {},
},
},
'昌平': {
'沙河': {
'老男孩': {},
'北航': {},
},
'天通苑': {},
'回龙观': {},
},
'朝阳': {},
'东城': {},
},
'上海': {
'闵行': {
"人民广场": {
'炸鸡店': {}
}
},
'闸北': {
'火车战': {
'携程': {}
}
},
'浦东': {},
},
'山东': {},
}
layers = [
menu,
]
while True:
if len(layers) == 0: break
current_layer = layers[-1]
for key in current_layer:
print(key)
choice = input('>>: ').strip()
if choice == 'b':
layers.pop(-1)
continue
if choice == 'q': break
if choice not in current_layer: continue
layers.append(current_layer[choice])