三级菜单
Posted bugpudge
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了三级菜单相关的知识,希望对你有一定的参考价值。
# _*_coding:utf-8_*_
menu = {
‘北京‘: {
‘海淀‘: {
‘五道口‘: {
‘soho‘: {},
‘网易‘: {},
‘google‘: {}
},
‘中关村‘: {
‘爱奇艺‘: {},
‘汽车之家‘: {},
‘youku‘: {},
},
‘上地‘: {
‘百度‘: {},
},
},
‘昌平‘: {
‘沙河‘: {
‘老男孩‘: {},
‘北航‘: {},
},
‘天通苑‘: {},
‘回龙观‘: {},
},
‘朝阳‘: {},
‘东城‘: {},
},
‘上海‘: {
‘闵行‘: {
"人民广场": {
‘炸鸡店‘: {}
}
},
‘闸北‘: {
‘火车战‘: {
‘携程‘: {}
}
},
‘浦东‘: {},
},
‘山东‘: {},
}
# 城市级别
citylevel = menu.copy()
# 目录级别
menulevel = 0
# 目录级别存储集合
citylevelup = {}
# 循环
while True:
# 输入起始城市
for i in citylevel:
print(i.center(10, ‘-‘))
strinput = input(‘输入城市,退出输入exit‘).strip()
# 如何输入的城市在列表中,将本目录的级别menulevel存入citylevelup{}
if strinput in citylevel:
print(strinput)
citylevelup[menulevel] = citylevel.copy() # 存储当前级别,索引+1
citylevel = citylevel[strinput]
menulevel += 1
continue
elif strinput == ‘exit‘:
break
# 如何输入back返回上一级,索引-1
elif strinput == ‘back‘ and menulevel != 0:
menulevel -= 1
citylevel = citylevelup[menulevel]
else:
print(‘您输入的值不存在,请重新输入‘)
print(‘程序结束‘)
以上是关于三级菜单的主要内容,如果未能解决你的问题,请参考以下文章