python入门第八天_练习

三级菜单:

 1 three_menu={
 2     '江苏':{'南京':{'栖霞区':'好地方',
 3                 '雨花台':'著名景点'
 4                 },
 5           '常州':{
 6               '新北区':'高新技术开发区',
 7               '武进区':'历史文化名城',
 8               '恐龙园':'生态旅游基地'
 9                 }
10           },
11     '安徽':{
12         '合肥':{
13             '好地方':'肥水之畔',
14             '死战之地':'很重要'
15         },
16         '蚌埠':{}
17 
18     },
19     '浙江':{
20         '杭州':{
21 
22             '瘦西湖':'都是水',
23             '雷峰塔':'我的泪'
24         },
25         '金华':{
26             '火腿肠':'真好吃',
27             '王中王':'品牌'
28         }
29     }
30 
31 
32 }
33 
34 for i in three_menu.keys():
35     print(i,end='\t')
36 
37 first_flag=True
38 second_flage=True
39 three_flag=True
40 
41 while first_flag:
42     get_first_menu = input('请输入要查看的省份:【Q/放弃】')
43     if get_first_menu.lower()=='q':
44         break
45     elif get_first_menu in three_menu:
46         for j in three_menu[get_first_menu]:
47             print(j,end='\t')
48         while second_flage:
49             get_second_menu=input("请输入要查看的城市:【b/返回上一级】【q/放弃】")
50             if get_second_menu.lower()=='q':
51                 first_flag=False
52                 break
53             elif get_second_menu.lower()=='b':
54                 break
55             elif get_second_menu in three_menu[get_first_menu]:
56                 for x in three_menu[get_first_menu][get_second_menu]:
57                     print(x,end='\t')
58                 while three_flag:
59                     get_three_menu=input('请输入要查看的区域:【b/返回上一级】【q/放弃】')
60                     if get_three_menu.lower()=='q':
61                         first_flag = False  #
62                         second_flage=False
63                         break
64                     elif get_three_menu.lower()=='b':
65                         break
66                     elif get_three_menu in three_menu[get_first_menu][get_second_menu]:
67                         print(three_menu[get_first_menu][get_second_menu][get_three_menu])
68                     else:
69                         print("查找不到,请重新输入")
70 
71             else:
72                 print("查找不到,请重新输入")
73 
74 
75 
76 
77     else:
78         print("查找不到,请重新输入")

 

 

 1 three_menu={
 2     '江苏':{'南京':{'栖霞区':'好地方',
 3                 '雨花台':'著名景点'
 4                 },
 5           '常州':{
 6               '新北区':'高新技术开发区',
 7               '武进区':'历史文化名城',
 8               '恐龙园':'生态旅游基地'
 9                 }
10           },
11     '安徽':{
12         '合肥':{
13             '好地方':'肥水之畔',
14             '死战之地':'很重要'
15         },
16         '蚌埠':{}
17 
18     },
19     '浙江':{
20         '杭州':{
21 
22             '瘦西湖':'都是水',
23             '雷峰塔':'我的泪'
24         },
25         '金华':{
26             '火腿肠':'真好吃',
27             '王中王':'品牌'
28         }
29     }
30 
31 
32 }
33 
34 #parent_dic={'current_key':'three','''first_key':'','second_key':'','three_key':''}
35 key_layers=[]
36 current_key=three_menu
37 while True:
38     for key in current_key:
39         print(key)
40 
41     get_key=input('>>> [b/back]/[q/quit]').strip()
42     if len(get_key)==0:continue
43     if get_key in current_key:
44         key_layers.append(current_key)
45         current_key=current_key[get_key]
46 
47     elif get_key.lower()=='b':
48         if key_layers:
49             current_key=key_layers.pop()
50 
51     elif get_key.lower()=='q':
52         break
53 
54     else:
55         print('无此项')

 

posted @ 2018-06-07 12:29  巨兽~墨菲特  阅读(108)  评论(0编辑  收藏  举报