字典_ 三级菜单

 1 #author:leon
 2 data = {
 3     '北京':{
 4         '昌平':{
 5             "沙河":["oldboy","test"],
 6             "天通苑":["链家","我爱我家"]
 7         },
 8         '朝阳':{
 9             "望京":["奔驰","陌陌"],
10             "国贸":["CCTV","hp"],
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 while  True:
38     for i in data:
39         print(i)
40     choice = input("选择进入>>>:")
41     if choice in data:
42         while True:
43             for i2 in data[choice]:
44                 print("\t",i2)
45             choice2= input("选择进入>>>:")
46             if choice2  in data[choice]:
47                 while True:
48                     for i3  in  data[choice][choice2]:
49                         print("\t\t",i3)
50                     choice3 = input("选择进入>>>:")
51                     if  choice3 in data[choice][choice2]:
52                         while True:
53                             for i4 in data[choice][choice2][choice3]:
54                                 print("\t\t\t", i4)
55                             choice4= input("最后一层,按q返回>>>:")
56                             if choice4== 'q':
57                                 break  #pass表示什么也不做,是占位符
58                     if choice3 == 'q':
59                         break
60             if choice2 == 'q':
61                 break

 

posted @ 2018-02-09 09:22  leon-zyl  阅读(158)  评论(0编辑  收藏  举报