三级菜单(1)
来源:互联网 发布:淘宝店铺手机怎么激活 编辑:程序博客网 时间:2024/06/01 10:44
要求:省市县三级菜单查询,可返回上级,可任意级退出
# -*- coding: utf-8 -*-# @Author: oppend# @Date: 2017-07-27 23:10:46# @Last Modified by: oppend# @Last Modified time: 2017-07-29 23:26:57# 省市区三级菜单import oscity = {"北京市":{"北京市":["东城区","西城区","朝阳区","丰台区"] }, "天津市":{"天津市":["和平区","河东区","河西区","南开区","河北区"], "经开区":["经开西区","经开东区"] } }sheng = sorted(list(city.keys()))back_flag = Falseexit_flag = Falsewhile not back_flag and not exit_flag: # 输出省列表 print('-----省-----') for snum,sname in enumerate(sheng,1): print('[{0}]{1}'.format(snum,sname)) choice_sheng = input('省序号[q]退出:') os.system('clear') # 判断是否为数字 if choice_sheng.isdigit(): choice_sheng = int(choice_sheng)-1 # 判断省序号范围 if choice_sheng >= len(sheng) or choice_sheng < 0: print('序号{0}错误'.format(choice_sheng+1)) continue # 根据序号取省名称 while not back_flag and not exit_flag: sheng_name = sheng[choice_sheng] shi = sorted(list(city[sheng_name].keys())) # 输出市列表 print('-----市-----') for shi_num,shi_name in enumerate(shi,1): print('[{0}]{1}'.format(shi_num,shi_name)) choice_shi = input('市序号[u]回上级[q]退出:') os.system('clear') if choice_shi.isdigit(): choice_shi = int(choice_shi)-1 # 判断市序号范围 if choice_shi >= len(shi) or choice_shi < 0: print('序号{0}错误'.format(choice_shi+1)) continue # 根据序号取市名称 while True: shi_name = shi[choice_shi] xian_list = city[sheng_name][shi_name] # 输出县列表 print('-----县-----') for xian_num,xian_name in enumerate(xian_list,1): print('[{0}]{1}'.format(xian_num,xian_name)) choice_xian = input('[u]回上级[q]退出:') os.system('clear') if not choice_xian.isdigit(): if choice_xian.lower() == 'u': break elif choice_xian.lower() == 'q': back_flag = True exit_flag = True break else: print('命令错误!') else: if choice_shi.lower() == 'u': break elif choice_shi.lower() == 'q': back_flag = True exit_flag = True break else: print('序号{0}不存在!'.format(choice_shi)) else: if choice_sheng.lower() == 'q': break else: print('序号{0}不存在!'.format(choice_sheng))
阅读全文
0 0
- 三级菜单(1)
- 三级菜单
- 三级菜单
- 三级菜单
- 三级菜单
- 三级菜单
- 三级菜单
- 三级菜单
- 三级菜单
- 三级菜单
- 三级菜单
- 仿QQ菜单----三级菜单
- 三级联动菜单
- 关联菜单.三级
- JS 三级联动菜单
- javascript三级下拉菜单
- 三级下拉菜单 (通用版):
- 下拉三级菜单
- 7.3 TensorFlow笔记(基础篇):加载数据之从队列中读取
- 第二个程序之图像腐蚀
- LeetCode 15. 3Sum -- 数组中某三个元素之和为0,输出这三个元素的值,且这个三元组唯一
- HDU 6078 Wavel Sequence 计数dp(思维)
- HDU-2017 多校训练赛4-1012-Wavel Sequence
- 三级菜单(1)
- 使用python3 连接SQL SERVER 2016
- 2017.08.05小结
- 字符串转整数函数stoi()实现
- 哈密尔顿环
- Git 原理 流程 命令
- 三角形判定
- 三级菜单(2)优化
- TensorFlow Session使用的两种方法