码迷,mamicode.com
首页 > 编程语言 > 详细

python 三级菜单

时间:2018-02-07 19:51:02      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:str   回退   class   tin   menu   strip   pen   int   div   

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 三级菜单

标签:str   回退   class   tin   menu   strip   pen   int   div   

原文地址:https://www.cnblogs.com/fuyuteng/p/8427344.html

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