Python(5)-简单练习:Python三级菜单优化

Python(5)-简单练习:Python三级菜单优化

 

python三级菜单优化,菜鸟版链接:http://www.cnblogs.com/xuyaping/p/6648170.html

1
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
menu  =  {
     '北京' :{
         '海淀' :{
             '五道口' :{
                 'soho' :{},
                 '网易' :{},
                 'google' :{}
             },
             '中关村' :{
                 '爱奇艺' :{},
                 '汽车之家' :{},
                 'youku' :{},
             },
             '上地' :{
                 '百度' :{},
             },
         },
         '昌平' :{
             '沙河' :{
                 '北航' :{},
             },
             '天通苑' :{},
             '回龙观' :{},
         },
         '朝阳' :{},
         '东城' :{},
     },
     '上海' :{
         '闵行' :{
             "人民广场" :{
                 '炸鸡店' :{}
             }
         },
         '闸北' :{
             '火车战' :{
                 '携程' :{}
             }
         },
         '浦东' :{},
     },
     '山东' :{},
}
 
current_layer = menu         #当前层
last_layers = [menu]         #上一层
while  True :
     for  key  in  current_layer:          #打印第一层菜单
         print (key)
     choice = input ( ">>:" ).strip()        #选择第二层菜单
     if  choice  in  current_layer:            
         last_layers.append(current_layer)         #进入下一层菜单前,把当前层菜单加入上一次菜单中
         current_layer = current_layer[choice]       #当前层菜单被重新定义,进入循环打印下一层菜单
     if  choice = = 0 :                                 #选择菜单层为空,结束本次循环
         continue
     if  choice = = "q" :                              #选择菜单层为“q”,结束本层循环
         break
     if  choice = = "b" :                              #选择菜单层为“b”,返回上一层菜单
         current_layer = last_layers[ - 1 ]            #返回上一层菜单前,当前层被重新定义
         last_layers.pop()                        #删除最后一次进入下一层菜单所加入的上一层列表数据
print ( "程序结束!" )

  

 
 
 
 

python三级菜单优化,菜鸟版链接:http://www.cnblogs.com/xuyaping/p/6648170.html

1
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
menu  =  {
     '北京' :{
         '海淀' :{
             '五道口' :{
                 'soho' :{},
                 '网易' :{},
                 'google' :{}
             },
             '中关村' :{
                 '爱奇艺' :{},
                 '汽车之家' :{},
                 'youku' :{},
             },
             '上地' :{
                 '百度' :{},
             },
         },
         '昌平' :{
             '沙河' :{
                 '北航' :{},
             },
             '天通苑' :{},
             '回龙观' :{},
         },
         '朝阳' :{},
         '东城' :{},
     },
     '上海' :{
         '闵行' :{
             "人民广场" :{
                 '炸鸡店' :{}
             }
         },
         '闸北' :{
             '火车战' :{
                 '携程' :{}
             }
         },
         '浦东' :{},
     },
     '山东' :{},
}
 
current_layer = menu         #当前层
last_layers = [menu]         #上一层
while  True :
     for  key  in  current_layer:          #打印第一层菜单
         print (key)
     choice = input ( ">>:" ).strip()        #选择第二层菜单
     if  choice  in  current_layer:            
         last_layers.append(current_layer)         #进入下一层菜单前,把当前层菜单加入上一次菜单中
         current_layer = current_layer[choice]       #当前层菜单被重新定义,进入循环打印下一层菜单
     if  choice = = 0 :                                 #选择菜单层为空,结束本次循环
         continue
     if  choice = = "q" :                              #选择菜单层为“q”,结束本层循环
         break
     if  choice = = "b" :                              #选择菜单层为“b”,返回上一层菜单
         current_layer = last_layers[ - 1 ]            #返回上一层菜单前,当前层被重新定义
         last_layers.pop()                        #删除最后一次进入下一层菜单所加入的上一层列表数据
print ( "程序结束!" )

  

猜你喜欢

转载自www.cnblogs.com/yimiflh/p/9280364.html