编程语言
首页 > 编程语言> > python实现三级菜单

python实现三级菜单

作者:互联网

多级菜单实现任务:

代码实现:

 1 #Author:AZ
 2 
 3 data = {
 4     '北京':{
 5         "昌平":{
 6             "沙河":["old boy","test"],
 7             "天通苑":["链家地产","我爱我家"]
 8         },
 9         "朝阳":{
10             "望京":["奔驰","陌陌"],
11             "国贸":["CICC","HP"],
12             "东直门":["Advent","飞信"]
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 exit_flag = False
45 
46 while not exit_flag:
47     for i in data:
48         print(i)
49     choice = input("选择进入1>>>:")
50     if choice in data:
51         while not exit_flag:
52             for i2 in data[choice]:
53                 print("\t",i2)
54             choice2 = input("选择输入2>>:")
55             if choice2 in data[choice]:
56                 while not exit_flag:
57                     for i3 in data[choice][choice2]:
58                         print("\t\t",i3)
59                     choice3 = input("选择进入3>>:")
60                     if choice3 in data[choice][choice2]:
61                         for i4 in data[choice][choice2][choice3]:
62                             print("\t\t",i4)
63                         choice4 = input("最后一层,按b返回>>:")
64                         if choice4=="b":
65                             pass
66                         elif choice4=='q':
67                             exit_flag=True
68                     if choice3=='b':
69                         break
70                     elif choice3 =="q":
71                         exit_flag=True
72             if choice2 =='b':
73                 break
74             elif choice2=="q":
75                 exit_flag = True
3level_menus.py

 

标签:菜单,python,choice2,choice,flag,exit,choice3,data,三级
来源: https://www.cnblogs.com/dylan123/p/Dylan.html