标签:
#!/usr/bin/env python
#coding:utf-8
#Auto:Panwenbin
#function:
#!/usr/bin/env python
#coding:utf-8
#Auto:Panwenbin
#function:
dict = {
‘北京市‘: {
‘海淀区‘: [‘中关村‘, ‘安贞‘, ‘西直门‘, ‘西苑‘],
‘东城区‘: [‘东直门‘, ‘王府井‘, ‘灯市口‘, ‘东四‘],
‘朝阳区‘: [‘呼家楼‘, ‘十里堡‘, ‘四惠‘, ‘燕莎‘, ‘亮马桥‘],
‘丰台区‘: [‘宋家庄‘, ‘大红门‘, ‘角门‘, ‘陶然亭‘]
},
‘上海市‘: {
‘浦东新区‘: [‘金桥‘, ‘洋泾‘, ‘塘桥‘, ‘八佰伴‘],
‘黄浦区‘: [‘外滩‘, ‘南京东路‘, ‘董家渡‘, ‘江宁路‘],
‘虹口区‘: [‘提篮桥‘, ‘长阳路‘, ‘临平路‘, ‘四平路‘],
‘普陀区‘: [‘长征‘, ‘真如‘, ‘梅川路‘, ‘金沙江路‘]
}
}
print( ‘‘‘
------------------------------------
+
+ \033[31m 欢迎进入全国地区查询系统 \033[0m
+
------------------------------------‘‘‘)
zone_name=list(dict.keys())
while True:
for index,key in enumerate(dict.keys()):
print(‘%d:%s‘%(index,key))
sheng_name=input(‘选择对应的数字进入相应的区域,按q退出程序:‘)
if sheng_name==‘q‘:
print(‘程序已退出‘)
exit()
elif sheng_name.isdigit() and int(sheng_name)< 3:
sheng_name=int(sheng_name)
if int(sheng_name)==sheng_name:
sheng=zone_name[sheng_name]
shi_name=dict[sheng]
shi_name=list(shi_name)
for i in range(len(shi_name)):
print(‘%d:%s‘%(i,shi_name[i]))
#city_name=input(‘选择对应的数字进入相应的区域,按b返回上一级,按q退出程序:‘)
while True:
area_name=input(‘‘‘\033[33m 选择对应的数字进入相应的区域,
按y返回第一级,按b返回上一级(第二级直接Y返回),按q退出程序: \033[0m ‘‘‘)
if area_name.isdigit() and int(area_name) < int(len(shi_name)):
area_name=int(area_name)
for a,b in enumerate(dict[sheng][shi_name[area_name]]):
print(‘%d:%s‘%(a,b))
elif area_name==‘q‘:
exit()
elif area_name==‘y‘:
break
elif area_name==‘b‘:
for i in range(len(shi_name)):
print(‘%d:%s‘%(i,shi_name[i]))
continue
else:
print(‘无效选项,请重新输入‘)
else:
print(‘非法输入,程序已退出‘)
exit()
标签:
原文地址:http://www.cnblogs.com/panwenbin-logs/p/5492169.html