# -*- coding: utf-8 -*-
# @Time : 2020/7/31 0:13
# @Author : Breeze
# @FileName: 三级菜单.py menu = {
'北京':{
'朝阳':{
'国贸':{
'CICC':{},
'HP':{},
'渣打银行':{}
},
'望京':{
'陌陌':{},
'奔驰':{},
'360':{},
},
'三里屯':{
'优衣库':{},
'apple':{},
},
},
'昌平':{
'沙河':{
'老男孩':{},
'阿泰包子':{}
},
'天通苑':{
'链家':{},
'我爱我家':{},
},
'回龙观':{},
},
'海淀':{
'五道口':{
'谷歌':{},
'网易':{},
'快手':{},
'SOHU':{},
'SOGO':{},
},
'中关村':{
'YOUKU':{},
'IQIYI':{},
'汽车之家':{},
'新东方':{},
'QQ':{},
},
},
},
'上海':{
'浦东':{
'陆家嘴':{
'CICC':{},
'高盛':{},
'摩根':{},
},
'外滩':{},
},
'闵行':{},
'静安':{}, },
'山东':{
'济南':{},
'德州':{
'乐陵':{
'丁务镇':{},
'城区':{},
},
'平原':{},
},
'青岛':{},
}
} back_flag = False
exit_flag = False
while not back_flag and not exit_flag:
for key in menu:
print(key)
choice = input('>>>:').strip()
if choice in menu:
while not back_flag and not exit_flag:
for key2 in menu[choice]:
print(key2)
choice2 = input('>>>:').strip()
if choice2 == 'b':
back_flag = True
if choice2 == 'q':
exit_flag = True
if choice2 in menu[choice]:
while not back_flag and not exit_flag:
for key3 in menu[choice][choice2]:
print(key3)
choice3 = input('>>>:').strip()
if choice3 == 'b':
back_flag = True
if choice3 == 'q':
exit_flag = True
if choice3 in menu[choice][choice2]:
while not back_flag and not exit_flag:
for key4 in menu[choice][choice2][choice3]:
print(key4)
choice4 = input('>>>:').strip()
print('last level')
if choice4 == 'b':
back_flag = True
if choice4 == 'q':
exit_flag = True
else:
back_flag = False
else:
back_flag = False
else:
back_flag = False
# -*- coding: utf-8 -*-
# @Time : 2020/7/31 1:29
# @Author : Breeze
# @FileName: 三级菜单high.py menu = {
'北京':{
'朝阳':{
'国贸':{
'CICC':{},
'HP':{},
'渣打银行':{}
},
'望京':{
'陌陌':{},
'奔驰':{},
'360':{},
},
'三里屯':{
'优衣库':{},
'apple':{},
},
},
'昌平':{
'沙河':{
'老男孩':{},
'阿泰包子':{}
},
'天通苑':{
'链家':{},
'我爱我家':{},
},
'回龙观':{},
},
'海淀':{
'五道口':{
'谷歌':{},
'网易':{},
'快手':{},
'SOHU':{},
'SOGO':{},
},
'中关村':{
'YOUKU':{},
'IQIYI':{},
'汽车之家':{},
'新东方':{},
'QQ':{},
},
},
},
'上海':{
'浦东':{
'陆家嘴':{
'CICC':{},
'高盛':{},
'摩根':{},
},
'外滩':{},
},
'闵行':{},
'静安':{}, },
'山东':{
'济南':{},
'德州':{
'乐陵':{
'丁务镇':{},
'城区':{},
},
'平原':{},
},
'青岛':{},
}
} current_layer = menu#实现动态循环
parent_layers = []#保存所有父级,最后一个元素永远是父级
while True:
for key in current_layer:
print(key)
choice = input('>>>:').strip()
if len(choice) == 0:
continue
if choice in current_layer:
parent_layers.append(current_layer)#在进入下一层之前,把当前层(也就是下一层父级)追加到列表中
#下一次loop,当用户选择b的时候,就可以直接去列表中最后一个值
current_layer = current_layer[choice]#改成了子层
elif choice == 'b' and parent_layers:
current_layer = parent_layers.pop()#取出列表中的最后一个值,因为他是当前层的父级
else:print('无此项')

最新文章

  1. 参数命令化 防止Sql注入
  2. JS组件系列——Bootstrap Select2组件使用小结
  3. Oracle删除所有表
  4. DIV------使用 <div> 元素的网页布局
  5. ubuntu 12.04 安装nginx
  6. UVA 712-S-Trees(满二叉树的简单查询)
  7. windows7下virtualBox配置识别usb
  8. springMVC,spring,mybatis全注解搭建框架--第一步,让框架跑起来
  9. 【easy】572. Subtree of Another Tree
  10. 分布式session解决——Spring-data-redis
  11. Delphi使用两种不同方法获取系统端口信息--(装载)
  12. Java爬虫框架Jsoup学习记录
  13. Linux环境下使用tcpdump抓包与下载
  14. Linux Centos下安装jdk
  15. 第一章:HTML5的基础
  16. java.io.Serializable中serialVersionUID的作用
  17. U3D的有限状态机系统
  18. django 项目中使用多数据库 multiple databases
  19. python第三方库——xlrd和xlwt操作Excel文件学习
  20. 第三次博客作业JSF

热门文章

  1. java8 升级 17 兼容测试 emt4j
  2. 【Anaconda】Jupyter 中添加 Anaconda 环境
  3. 连接Oracle 19c出现ORA-28040:没有匹配的验证协议
  4. COM三大接口:IUnknown、IClassFactory、IDispatch。
  5. 一些test短代码
  6. Unity Shader实现《死亡搁浅》扫描效果!
  7. docker方式安装awvs和nessus渗透工具
  8. CSP2022 J2参考解析
  9. 查看Linux操作系统版本命令
  10. ORACLE备份脚本(4-RMAN1级增量备份)