标签:pre 上海 ack 山东 menu 爱奇艺 循环 老男孩 城市
# _*_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(‘程序结束‘)
标签:pre 上海 ack 山东 menu 爱奇艺 循环 老男孩 城市
原文地址:https://www.cnblogs.com/BugPudge/p/8889571.html