zoukankan      html  css  js  c++  java
  • 三级菜单

    三级菜单:
    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') #选择物品不在名单里
  • 相关阅读:
    Open source cryptocurrency exchange
    Salted Password Hashing
    95. Unique Binary Search Trees II
    714. Best Time to Buy and Sell Stock with Transaction Fee
    680. Valid Palindrome II
    Java compiler level does not match the version of the installed Java project facet.
    eclipse自动编译
    Exception in thread "main" java.lang.StackOverflowError(栈溢出)
    博客背景美化——动态雪花飘落
    java九九乘法表
  • 原文地址:https://www.cnblogs.com/nikitapp/p/5956858.html
Copyright © 2011-2022 走看看