006菜单练习(标记位)

python学习网 2017-12-07 06:22:02

 

 退出程序不用exit()

 

#01代码

 1 #__author: _nbloser
 2 #date: 2017/12/5
 3 
 4 
 5 shaoguan = ['仁化', '始兴', '乐昌', '南雄']
 6 jiangmeng = ['开平', '蓬江', '台山', '鹤山', '恩平']
 7 guangdong_province = {'韶关':shaoguan, '江门':jiangmeng}
 8 
 9 nanchang = ['东湖', '西湖', '新建', '安义', '进贤']
10 jingdezhen = ['昌江', '珠山', '乐平', '浮梁']
11 jiangxi_province = {'南昌':nanchang, '景德镇':jingdezhen}
12 
13 provinces = {'广东':guangdong_province, '江西':jiangxi_province}
14 
15 def pr(array):
16     for i in array:
17         print(i, end="  ")
18     print()
19 
20 while True:
21     print("省份:", end="")
22     name_province = list(provinces.keys())
23     #print(name_province)
24     pr(name_province)
25     pro_input = input("输入你要查看的省份/输入exit退出:")
26     if pro_input == 'exit':
27         exit()
28     if pro_input not in pro_input:
29         print("没有该省份!")
30         continue
31     while True:
32         tmp_province = provinces[pro_input]
33         name_shis = list(tmp_province.keys())
34         #print(tmp_province)
35         pr(name_shis)
36         shi_input = input("输入你要查看的市/输入exit退出/输入return返回上一层:")
37         if shi_input == 'exit':
38             exit()
39         if shi_input == 'return':
40             break
41         if shi_input not in tmp_province:
42             print("没有该市!")
43             continue
44         while True:
45             tmp_county = tmp_province[shi_input]
46             pr(tmp_county)
47             county_input = input("输入exit退出/输入return返回上一层:")
48             if county_input == 'exit':
49                 exit()
50             if county_input == 'return':
51                 break
View Code

 

阅读(777) 评论(0)