python菜单栏教程(Python3.5实现的三级菜单功能示例)
类别:脚本大全 浏览量:1927
时间:2021-10-28 10:26:04 python菜单栏教程
Python3.5实现的三级菜单功能示例本文实例讲述了Python3.5实现的三级菜单功能。分享给大家供大家参考,具体如下:
程序:三级菜单
要求:
1. 打印省、市、县三级菜单
2. 可返回上一级
3. 可随时退出程序
具体代码:
|
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author:ZhengzhengLiu Province_Data = { "北京市" :{ "朝阳区" :{ "南磨房地区" :[ "东郊社区" , "平乐园社区" ], "高碑店地区" :[ "兴隆家园社区" , "大黄庄社区" ], "将台地区" :[ "丽都社区" , "房里苑社区" ] }, "海淀区" :{ "万寿路街道" :[" "," "], "羊坊店街道" :[" "," "], "八里庄街道" :[" "," "] }, "怀柔区" :{ "怀柔镇" :[" "," "], "雁栖镇" :[" "," "], "城庙镇" :[" "," "] } }, "天津市" :{ "和平区" :{ "劝业场街道" :[" "," "], "小白楼街道" :[" "," "], "五大道街道" :[" "," "] }, "南开区" :{ "华苑街道" :[" "," "], "长虹街道" :[" "," "], "鼓楼街道" :[" "," "] }, "河西区" :{ "桃园街道" :[" "," "], "马场街道" :[" "," "], "大营门街道" :[" "," "] } }, "河北省" :{ "石家庄市" :{ "长安区" :[" "," "], "桥西区" :[" "," "], "新华区" :[" "," "] }, "廊坊市" :{ "安次区" :[" "," "], "广阳区" :[" "," "], "西小区" :[" "," "] }, "唐山市" :{ "路南区" :[" "," "], "路北区" :[" "," "], "古冶区" :[" "," "] } }, "山东省" :{ "青岛市" :{ "市南区" :[" "," "], "市北区" :[" "," "], "即墨市" :[" "," "] }, "济南市" :{ "历下区" :[" "," "], "市中区" :[" "," "], "槐荫区" :[" "," "] }, "烟台市" :{ "福山区" :[" "," "], "莱山区" :[" "," "], "牟平区" :[" "," "] } } } exit_flag = False #退出标志符 while not exit_flag: for i in Province_Data: print (i) user_choice = input ( "Please choose the province..." ) if user_choice in Province_Data: while not exit_flag: for j in Province_Data[user_choice]: print ( '\t' ,j) user_choice1 = input ( "Please choose the city..." ) if user_choice1 in Province_Data[user_choice]: while not exit_flag: for k in Province_Data[user_choice][user_choice1]: print ( '\t\t' ,k) user_choice2 = input ( "Please choose the communitiy..." ) if user_choice2 in Province_Data[user_choice][user_choice1]: while not exit_flag: for l in Province_Data[user_choice][user_choice1][user_choice2]: print ( '\t\t\t' ,l) user_choice3 = input ( "The last choose,please enter 'b' to back..." ) if user_choice3 = = 'b' : break elif user_choice3 = = 'q' : exit_flag = True if user_choice2 = = 'b' : break elif user_choice2 = = 'q' : exit_flag = True if user_choice1 = = 'b' : break elif user_choice1 = = 'q' : exit_flag = True #运行结果: ''' 山东省 河北省 天津市 北京市 Please choose the province...北京市 朝阳区 怀柔区 海淀区 Please choose the city...朝阳区 南磨房地区 将台地区 高碑店地区 Please choose the communitiy...将台地区 丽都社区 房里苑社区 The last choose,please enter 'b' to back...b 南磨房地区 将台地区 高碑店地区 Please choose the communitiy...b 朝阳区 怀柔区 海淀区 Please choose the city...b 山东省 河北省 天津市 北京市 Please choose the province...北京市 朝阳区 怀柔区 海淀区 Please choose the city...q Process finished with exit code 0 ''' |
希望本文所述对大家Python程序设计有所帮助。
原文链接:https://blog.csdn.net/loveliuzz/article/details/77750595
您可能感兴趣
- python网页自动化selenium(python利用selenium进行浏览器爬虫)
- pythonmatplotlib散点图怎么画(python使用matplotlib画柱状图、散点图)
- 如何利用python编写日期的程序(Python读取指定日期邮件的实例)
- pythonpandas操作拆分excel(Python使用pandas和xlsxwriter读写xlsx文件的方法示例)
- python 文本文件读取方法(Python逐行读取文件中内容的简单方法)
- 最简单python的100个代码(20条非常实用的Python代码实例)
- python静态方法和类方法的区别(Python实例方法、类方法、静态方法的区别与作用详解)
- python最基本的编程工具(5款Python程序员高频使用开发工具推荐)
- 如何查看python是否安装selenium(selenium+python截图不成功的解决方法)
- python 串口图形化(python使用MQTT给硬件传输图片的实现方法)
- python编写告白程序(python抖音表白程序源代码)
- pythontkinter项目界面(python Tkinter版学生管理系统)
- python3.7.0使用方法(Python3.5模块的定义、导入、优化操作图文详解)
- python yield 使用浅析(yii框架使用分页的方法分析)
- python代码返回值(Python 函数返回值的示例代码)
- 能自动点赞的小程序(python实现QQ空间自动点赞功能)
- 泰国美女(泰国人妖和女性如何区分)
- 泰国旅游业怎么样(泰国的旅游产业)
- 越南新娘(越南新娘婚介网站)
- 越南新娘(越南新娘骗婚套路流程)
- 菲律宾游学(菲律宾游学中介机构)
- 菲律宾美食(菲律宾美食排行榜前十名)
热门推荐
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9