码迷,mamicode.com
首页 > 其他好文 > 详细

关于三级菜单

时间:2019-05-19 12:30:06      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:数据结构   strip   升级   三级   网易   return   googl   汽车   数据   

#数据结构:
menu = {
‘北京‘:{
‘海淀‘:{
‘五道口‘:{
‘soho‘:{},
‘网易‘:{},
‘google‘:{}
},
‘中关村‘:{
‘爱奇艺‘:{},
‘汽车之家‘:{},
‘youku‘:{},
},
‘上地‘:{
‘百度‘:{},
},
},
‘昌平‘:{
‘沙河‘:{
‘老男孩‘:{},
‘北航‘:{},
},
‘天通苑‘:{},
‘回龙观‘:{},
},
‘朝阳‘:{},
‘东城‘:{},
},
‘上海‘:{
‘闵行‘:{
"人民广场":{
‘炸鸡店‘:{}
}
},
‘闸北‘:{
‘火车站‘:{
‘携程‘:{}
}
},
‘浦东‘:{},
},
‘山东‘:{},
}
while True:
for i in menu:
print(i)
choice = input(‘>‘).strip()
while True:
if choice in menu:
print(‘进入第一级‘)
for i in menu[choice]:
print(i)
choice2 = input(‘>>‘).strip()
if choice2 == ‘return‘:
print(‘返回上一层‘)
break
elif choice2 in menu[choice]:
pass
elif choice2 == ‘q‘:
exit()
else:
print(‘输入有误‘)
continue
while True:
if choice2 in menu[choice]:
print(‘进入第2级‘)
for i in menu[choice][choice2]:
print(i)
choice3 = input(‘>>>‘).strip()
if choice3 == ‘return‘:
print(‘返回上一级‘)
break
elif choice3 in menu[choice][choice2]:
pass
elif choice3 == ‘q‘:
exit()
else:
print(‘输入有误‘)
continue
while True:
if choice3 in menu[choice][choice2]:
print(‘进入第三级‘)
for i in menu[choice][choice2][choice3]:
print(i)
choice4 = input(‘如果返回输入return‘).strip()
if choice4 == ‘return‘:
print(‘返回上一级‘)
break
elif choice4 == ‘q‘:
exit()
else:
break
elif choice == ‘q‘:
exit()
else:
choice = input(‘>‘).strip()






#升级版本:
current_layer = menu
count = 0
up_layer = menu
while True:
for i in current_layer:
print(i)
choice = input(‘>‘).strip()
if not choice:continue
elif choice == ‘return‘:
current_layer = up_layer
continue
elif choice == ‘q‘:
exit()
elif choice in current_layer:
up_layer = current_layer
current_layer = current_layer[choice]
else:
print(‘重新输入‘)

关于三级菜单

标签:数据结构   strip   升级   三级   网易   return   googl   汽车   数据   

原文地址:https://www.cnblogs.com/rainbowupdate/p/10888555.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!