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

Python之三层菜单

时间:2016-01-11 21:46:56      阅读:387      评论:0      收藏:0      [点我收藏+]

标签:

三层菜单,根据用户所选数字,进入子菜单。一级一级呈现。
技术分享
 1 menu = {
 2     Beijing: {
 3         "ChaoYang": {
 4             "CBD": [CICC, CCTV],
 5             "JinRongJie": ["CT"],
 6             "Wangjing": ["Momo", "ChuiZI"]
 7         },
 8         "HaiDian": [Baidu, Youku]
 9     },
10     Shanghai: {
11         "PuDong": ["Ctrip", "One Shop"],
12         "PuXi": ["China Bank", "America Bank"]
13     }
14 }
15 exit_flag = False
16 while not exit_flag:
17     for index, key in enumerate(menu.keys()):
18         print(index, key)
19     choice_1 = input("Please choose menu to enter:").strip()
20     if choice_1.isdigit():
21         choice_1 = int(choice_1)
22 
23         key_1 = list(menu.keys())[choice_1]
24         while not exit_flag:
25             for index, key in enumerate(menu[key_1]):
26                 print(-->, index, key)
27             choice_2 = input("Please choose menu to enter:").strip()
28             if choice_2.isdigit():
29                 choice_2 = int(choice_2)
30 
31                 key_2 = list(menu[key_1].keys())[choice_2]
32                 while not exit_flag:
33                     for index, key in enumerate(menu[key_1][key_2]):
34                         print(-->-->, index, key)
35                     choice_3 = input("Please choose menu to enter:").strip()
36                     if choice_3.isdigit():
37                         print("This is the last level...")
38                     elif choice_3 == quit:
39                         exit_flag = True
40                     elif choice_3 == back:
41                         break
42 else:
43     print("====Going to quit==== ")
View Code

 注:此版本为Python3.0版本

Python之三层菜单

标签:

原文地址:http://www.cnblogs.com/ouyangyixuan/p/5122518.html

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