• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
nikitapp
博客园    首页    新随笔    联系   管理    订阅  订阅
三级菜单

三级菜单:
1. 运行程序输出第一级菜单
2. 选择一级菜单某项,输出二级菜单,同理输出三级菜单
3. 菜单数据保存在文件中

 1 # 创造三级菜单
 2 shoppingmall = {'clothes':{'skirt':['s', 'm', 'l'], 'shikt':['s', 'm', 'l'], 'coat':['s', 'm', 'l'],},
 3                 'phone':{'Apple':['5', '6', '7'], 'Xiaomi':['1', '2', '3'], 'Huawei':['6', '7', '8']},
 4                 'friut':{'apple':['1kg','2kg','3kg'],'pear':['1kg','2kg','3kg'], 'banana':['1kg','2kg','3kg']}}
 5 list1=[]
 6 list2=[]
 7 
 8 # 打印一级菜单
 9 total_count = 0
10 for x in range(3):
11     count = 0
12     for i in range(3):
13         for key in shoppingmall:
14             print(key)
15             list1.append(key)
16 # 选择一项到下一级菜单或者退出
17         choose = input('Please chose thing or q = quit:')
18         if choose == 'q':
19             exit('Bye!')
20 # 进入下一级菜单
21         elif choose in list1:
22             a = shoppingmall.get(choose)
23             count1 = 0
24             for y in range(3):
25                 for key1 in a:
26                     print(key1)
27                     list2.append(key1)
28 
29         # 选择一项到下一级菜单或者退出或返回
30                 choose1 = input('Please chose that you want or q = quit or b = back :')
31                 if choose1 == 'q':
32                     exit('Bye!')
33 
34                 elif choose1 == 'b':
35                     count += 1
36                     break
37                     if count == 3:  # 选择不能超过三次
38                         print('Sorry, your choose is over the limit.')
39                 elif choose1 in list2:
40                 # 进入下一级菜单
41                     b = a.get(choose1)
42                     for key2 in b:
43                         print(key2)
44     # 选择退出,返回上一级菜单 或者第一个菜单
45                     choose2 = input('Please chose that q = quit or b = back or 1st = the first list')
46                     if choose2 == 'q':
47                         exit('Bye!')
48                     elif choose2 == 'b':
49                         count1 += 1
50 
51                         if count1 == 3:
52                             print('Sorry, your choose is over the limit.')
53                             break
54                     elif choose2 == '1st':
55 
56                         total_count += 1
57                         break
58 
59                         if total_count == 3:
60                             print('Sorry, your choose is over the limit.')
61                     else:
62                         print('Sorry, your choose not in list! Please choose again')
63                 else:
64                     print('Sorry, your choose not in list!Please choose again')
65         else:
66             print('Sorry, your choose not in list! Please choose again') #选择物品不在名单里

 

posted on 2016-10-13 16:13  nikitapp  阅读(198)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3