3level_menus
# encoding: utf-8 # Creator:耿亚月 Creation time:2017-1-2
# Modifier:耿亚月 Modification time:2017-1-2 #输入选择的省、市、县
def choose(data, name, level):
for i in data:
print('\t'*level,i)
choice = input('选择进入{name},按b返回》,q退出:'.format(name=name))
return choice #输入选择是否返回上一层
def choose_back(place):
choice=input('Do you want to back to {where}? y/n:'.format(where=place))
return choice #输入选择是否退出
def choose_exit():
choice = input('Do you want to exit? y/n:')
if choice == 'y':
return True data = {
'北京': {
'昌平': {
'沙河': ['oldboy','test'],
'天通苑': ['链家地产','我爱我家'],
},
'朝阳': {
'望京': ['奔驰','陌陌'],
'国贸': ['CICC','HP'],
'东直门': ['Advent','飞信'],
},
'海淀': {},
},
'山东': {
'德州': {},
'青岛': {},
'济南': {},
},
'广东': {
'东莞': {},
'常熟': {},
'佛山': {},
},
} exit_flag = False
#省
while not exit_flag:
choice = choose(data, '省', 0)
if choice in data:
#市
while not exit_flag:
choice2 = choose(data[choice], '市', 1)
if choice2 in data[choice]:
#县
while not exit_flag:
choice3 = choose(data[choice][choice2], '县', 2)
if choice3 in data[choice][choice2]:
print(data[choice][choice2][choice3])
exit_flag = True
#县
elif choice3 == 'b':
if choose_back('县') == 'y':
break
elif choice3 == 'q':
exit_flag = choose_exit()
else:
print('Invalid choice,please try again')
#市
elif choice2 == 'b':
if choose_back('省') == 'y':
break
elif choice2 == 'q':
exit_flag = choose_exit()
else:
print('Invalid choice,please try again')
#省
elif choice == 'q':
exit_flag = choose_exit()
else:
print('Invalid choice,please try again')
3level_menus的更多相关文章
随机推荐
- 华为5700s配置链路聚合
/创建聚合链路,数值可以随意. port link-type trunk /设置成trunk模式.(如果是接入vlan的话,link-type acess) port trunk allow-pass ...
- nginx expires
配置expiresexpires起到控制页面缓存的作用,合理的配置expires可以减少很多服务器的请求要配置expires,可以在http段中或者server段中或者location段中加入 1 ...
- linux下的a.out文件
当然这里,我更重要的是强调这个什么段,什么段.这以前就知道.但其实是对一个可以执行的c语言程序的分析.就好比你分析一篇作文.有标题.有段落. .out文件就是扩展名为out的文件,它本身不代表任 ...
- shell 从1加到100
- UVA 11210 中国麻将
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 解决file_get_contents遇到中文文件名无法打开问题
利用file_get_contents打开文件或采集远程服务器文件如果文名或url中碰到汉字中文那么会出现failed to open stream:Lnvalid argument in错误. ...
- gbd基本使用一
http://biancheng.dnbcw.info/linux/391846.html
- 如何让老Mac机支持USB安装Windows
一些老Mac机的用户想装Windows,却发现自己的系统上的Boot Camp Assistant(以下简称BCA)没有USB安装Windows的选项. 下面以我的MacBook Pro (13-in ...
- hightcharts 3d 堆积图下钻
图片效果 ***************代码部分****************************************************** <!doctype html> ...
- html+js 的一些小问题
html+js 的一些小问题: 选择器+遍历函数: $("#taskStatusList tr:gt(0)").find("td:eq(3)").find(&q ...