码迷,mamicode.com
首页 > 编程语言 > 详细

python实现三级菜单

时间:2019-03-17 10:54:57      阅读:317      评论:0      收藏:0      [点我收藏+]

标签:choice   世纪   选择   close   python实现   []   返回   lse   data   

多级菜单实现任务:
  • 三级菜单
  • 可依次选择进入各子菜单
  • 所需新知识点:列表、字典

代码实现:

技术图片
 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实现三级菜单

标签:choice   世纪   选择   close   python实现   []   返回   lse   data   

原文地址:https://www.cnblogs.com/dylan123/p/Dylan.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!