006菜单练习(标记位)

2018-06-17 23:47:19来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

 

 退出程序不用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

 

#02plus_code

 1 #__author: _nbloser
 2 #date: 2017/12/5
 3 
 4 #plus
 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 back_flag = False
21 exit_flag = False
22 
23 while not exit_flag and not back_flag:
24     print("省份:", end="")
25     name_province = list(provinces.keys())
26     pr(name_province)
27     pro_input = input("输入你要查看的省份/输入q或b退出:")
28     if pro_input == 'q':
29         exit_flag = True
30     if pro_input == 'b':
31         back_flag = True
32     if pro_input in provinces:
33         while not exit_flag and not back_flag:
34             tmp_province = provinces[pro_input]
35             name_shis = list(tmp_province.keys())
36             pr(name_shis)
37             shi_input = input("输入你要查看的市/输入q退出/输入b返回上一层:")
38             if shi_input == 'q':
39                 exit_flag = True
40             if shi_input == 'b':
41                 back_flag = True
42             if shi_input in tmp_province:
43                 while not exit_flag and not back_flag:
44                     tmp_county = tmp_province[shi_input]
45                     pr(tmp_county)
46                     county_input = input("输入q退出/输入b返回上一层:")
47                     if county_input == 'q':
48                         exit_flag = True
49                     if county_input == 'b':
50                         back_flag = True
51                 else:
52                     back_flag = False
53         else:
54             back_flag = False
View Code

 

#03高大上code

 1 #__author: _nbloser
 2 #date: 2017/12/7
 3 #double puls
 4 shaoguan = ['仁化', '始兴', '乐昌', '南雄']
 5 jiangmeng = ['开平', '蓬江', '台山', '鹤山', '恩平']
 6 guangdong_province = {'韶关':shaoguan, '江门':jiangmeng}
 7 
 8 nanchang = ['东湖', '西湖', '新建', '安义', '进贤']
 9 jingdezhen = ['昌江', '珠山', '乐平', '浮梁']
10 jiangxi_province = {'南昌': nanchang, '景德镇': jingdezhen}
11 
12 provinces = {'广东': guangdong_province, '江西': jiangxi_province}
13 
14 current_layer = provinces
15 parent_layer = []
16 exit_flag = False
17 while not exit_flag:
18     for key in current_layer:
19         print(key, end=" ")
20     print()
21     choice = input(">>")
22     if choice in current_layer and type(current_layer) != list:
23         parent_layer.append(current_layer)
24         current_layer = current_layer[choice]
25     elif choice == 'b':
26         if parent_layer:
27             current_layer = parent_layer.pop()
28         else: break
29     elif choice == 'q':
30         exit_flag = True
31     else:
32         print("查无此项/为最底层!")
View Code

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Python数据分析中Groupby用法之通过字典或Series进行分组

下一篇:matplotlib注解-【老鱼学matplotlib】