Python字典实现简单的三级菜单(实例讲解)
2019/7/13 22:53:29
本文主要是介绍Python字典实现简单的三级菜单(实例讲解),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
如下所示:
data = { "北京":{ "昌平":{"沙河":["oldboy","test"],"天通苑":["链接地产","我爱我家"]}, "朝阳":{"望京":["奔驰","陌陌"],"国贸":["CICC","HP"],"东直门":["advent","飞信"]}, "海淀":{} }, "山东":{ "德州":{}, "青岛":{}, "济南":{} }, "广东":{ "东莞":{}, "常熟":{}, "佛山":{} } } exit_flag = False while not exit_flag: for i in data: print(i) choice_s = input("请输入以上任一省或直辖市名称>>>:") if choice_s in data: while not exit_flag: for i in data[choice_s]: print("\t",i) choice_q = input("请输入以上任一市区名称>>>:") if choice_q in data[choice_s]: while not exit_flag: for i in data[choice_s][choice_q]: print("\t\t",i) choice_j = input("请输入以上任一街道名称>>>:") if choice_j in data[choice_s][choice_q]: for i in data[choice_s][choice_q][choice_j]: print("\t\t",i) last = input("最后一层,按b返回>>>:") if last == "b": pass elif last == "q": exit_flag = True if choice_j == "b": break elif choice_j == "q": exit_flag = True if choice_q == "b": break elif choice_q == "q": exit_flag = True
要点:
1、字典的层级关系
2、break是终止本次循环,pass是什么也不做,一个占位符而已
3、巧妙使用exit_flag = False
以上这篇Python字典实现简单的三级菜单(实例讲解)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持找一找教程网。
这篇关于Python字典实现简单的三级菜单(实例讲解)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python