'''程序:三级菜单
要求:
1、打印省、市、县三级菜单
2、可返回上一级
3、可随时退出程序
'''
# -*- coding: utf-8 -*-
# __author__ = 'qi'
prov_city_conty ={"北京":
{"东城区","西城区","崇文区","宣武区","朝阳区","丰台区","石景山区","海淀区","顺义区"},
"上海":
{"黄埔区","卢湾区","徐汇区","长宁区","静安区","普陀区","闸北区","杨浦区","闵行区"},
"河北":
{
"石家庄市":
{"长安区","桥东区","桥西区","新华区","井陉矿区","裕华区"},
"唐山市":
{"路南区","路北区","古冶区","开平区","丰润区","滦县"}
},
"江苏":
{
"南京市":
{"玄武区","白下区","秦淮区","建邺区","鼓楼区","下关区","浦口区"},
"苏州市":
{"沧浪区","平江区","金阊区","吴中区","相城区","常熟市"}
}
}
while True:
print ("-----打印省菜单------")
for index,prov in enumerate(prov_city_conty,1):
print index, prov
choice_p_menu = raw_input("please select province number[quit:q]:")
if choice_p_menu.isdigit():
choice_p_menu = int(choice_p_menu)
if choice_p_menu>0 and choice_p_menu<len(prov_city_conty):
prov_name_list = prov_city_conty.keys()
prov_name = prov_name_list[choice_p_menu-1]
while True:
print ("-----"+prov_name+"------")
for index,city in enumerate(prov_city_conty[prov_name],1):
print index,city
if prov_name not in ["北京","上海"]:
choice_city_menu = raw_input("please select city number[quit:q]|[return:r]:")
if choice_city_menu.isdigit():
choice_city_menu = int(choice_city_menu)
if choice_city_menu>0 and choice_city_menu<len(prov_city_conty[prov_name]):
city_name_list = prov_city_conty[prov_name].keys()
city_name = city_name_list[choice_city_menu-1]
while True:
print ("-----"+city_name+"------")
for county in prov_city_conty[prov_name][city_name]:
print county
choice_q_r_menu = raw_input("please select [quit:q]|[return:r]:")
if choice_q_r_menu == "q":
exit()
elif choice_q_r_menu == "r":
break
else:
print("your input code %s is not exist!" %choice_q_r_menu)
continue
else:
print ("city code %s is not exist!" %choice_city_menu)
continue
elif choice_city_menu == "q":
exit()
elif choice_city_menu == "r":
break
else:
choice_q_r_menu = raw_input("please select [quit:q]|[return:r]:")
if choice_q_r_menu == "q":
exit()
elif choice_q_r_menu == "r":
break
else:
print("your input code %s is not exist!" %choice_q_r_menu)
continue
else:
print ("province code %s is not exist!" %choice_p_menu)
elif choice_p_menu == "q":
break