python 三级菜单

Posted 努力乄小白

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 三级菜单相关的知识,希望对你有一定的参考价值。

menu = {"北京":{"海淀":["知春路","公主坟","西土城","牡丹园"],"朝阳":["金台夕照","望京","青年路","三元桥"],"昌平":["天通苑","立水桥","沙河","西二旗"]},"哈尔滨":{"江北":["宾县","方正县","依兰县"],"南岗":["巴彦县","木兰县","延寿县","通河县"]

},"上海":{"杨浦区":["黄浦区","静安区","长宁区"],"虹口区":["卢湾区","徐汇区","闵行区"],"普陀区":["浦东新区","宝山区","松江区"]}}



current_layer = menu # 存放当前节点
pre_layer=[] #存放前面的节点数据


while True:
for i in current_layer:
print(i)
user_opt = input(">>:").strip()
if user_opt == None:
continue
elif user_opt == "q":
exit()
elif user_opt == "b":
if current_layer == menu:#若当前节点已是最顶层节点,则不回退
continue
else:
current_layer = pre_layer.pop()#回退一级,上一级节点变成当前节点
elif user_opt in current_layer:
pre_layer.append(current_layer)#前进一级,当前节点变为上一级节点
current_layer = current_layer[user_opt]#下一级节点变为当前节点

























以上是关于python 三级菜单的主要内容,如果未能解决你的问题,请参考以下文章

Python 三级菜单

python实现三级菜单

学习Python的第二十天三级菜单高级版

python3.5------三级菜单

Python作业二:三级列表

python之三级菜单