'''程序:三级菜单
要求:
1、打印省、市、县三级菜单
2、可返回上一级
3、可随时退出程序
'''
1 # -*- coding: utf-8 -*-
2 # __author__ = 'qi'
3 prov_city_conty ={"北京":
4 {"东城区","西城区","崇文区","宣武区","朝阳区","丰台区","石景山区","海淀区","顺义区"},
5 "上海":
6 {"黄埔区","卢湾区","徐汇区","长宁区","静安区","普陀区","闸北区","杨浦区","闵行区"},
7 "河北":
8 {
9 "石家庄市":
10 {"长安区","桥东区","桥西区","新华区","井陉矿区","裕华区"},
11 "唐山市":
12 {"路南区","路北区","古冶区","开平区","丰润区","滦县"}
13 },
14 "江苏":
15 {
16 "南京市":
17 {"玄武区","白下区","秦淮区","建邺区","鼓楼区","下关区","浦口区"},
18 "苏州市":
19 {"沧浪区","平江区","金阊区","吴中区","相城区","常熟市"}
20 }
21 }
22 while True:
23 print ("-----打印省菜单------")
24 for index,prov in enumerate(prov_city_conty,1):
25 print index, prov
26 choice_p_menu = raw_input("please select province number[quit:q]:")
27 if choice_p_menu.isdigit():
28 choice_p_menu = int(choice_p_menu)
29 if choice_p_menu>0 and choice_p_menu<len(prov_city_conty):
30 prov_name_list = prov_city_conty.keys()
31 prov_name = prov_name_list[choice_p_menu-1]
32 while True:
33 print ("-----"+prov_name+"------")
34 for index,city in enumerate(prov_city_conty[prov_name],1):
35 print index,city
36 if prov_name not in ["北京","上海"]:
37 choice_city_menu = raw_input("please select city number[quit:q]|[return:r]:")
38 if choice_city_menu.isdigit():
39 choice_city_menu = int(choice_city_menu)
40 if choice_city_menu>0 and choice_city_menu<len(prov_city_conty[prov_name]):
41 city_name_list = prov_city_conty[prov_name].keys()
42 city_name = city_name_list[choice_city_menu-1]
43 while True:
44 print ("-----"+city_name+"------")
45 for county in prov_city_conty[prov_name][city_name]:
46 print county
47 choice_q_r_menu = raw_input("please select [quit:q]|[return:r]:")
48 if choice_q_r_menu == "q":
49 exit()
50 elif choice_q_r_menu == "r":
51 break
52 else:
53 print("your input code %s is not exist!" %choice_q_r_menu)
54 continue
55 else:
56 print ("city code %s is not exist!" %choice_city_menu)
57 continue
58 elif choice_city_menu == "q":
59 exit()
60 elif choice_city_menu == "r":
61 break
62 else:
63 choice_q_r_menu = raw_input("please select [quit:q]|[return:r]:")
64 if choice_q_r_menu == "q":
65 exit()
66 elif choice_q_r_menu == "r":
67 break
68 else:
69 print("your input code %s is not exist!" %choice_q_r_menu)
70 continue
71 else:
72 print ("province code %s is not exist!" %choice_p_menu)
73 elif choice_p_menu == "q":
74 break