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

    要求: 

    1. 打印省、市、县三级菜单
    2. 可返回上一级
    3. 可随时退出程序
     1 menu = {
     2     '北京':{
     3         '海淀':{
     4             '五道口':{
     5                 'soho':{},
     6                 '网易':{},
     7                 'google':{}
     8             },
     9             '中关村':{
    10                 '爱奇艺':{},
    11                 '汽车之家':{},
    12                 'youku':{},
    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 
    45 current_level = menu
    46 last_level = []
    47 
    48 while True:
    49     for key in current_level: #打印第一层
    50         print(key)
    51     choice = input(">>:").strip()  #输入你要进去的
    52     if len(choice) == 0 :continue #输入的choice为空,则continue
    53     if choice == "b": #输入b,退回上一次
    54         if len(last_level) == 0:break #退到头了,在再退就退出了
    55         current_level = last_level[-1] #-1代表最后一位
    56         last_level.pop() #需要删除最后一位,才能持续后退
    57     if choice not in current_level:continue #输入的choice不在字典中,则continue
    58     last_level.append(current_level)  #记住当前层
    59     current_level = current_level[choice] #进入下一层
  • 相关阅读:
    jquery实现章节目录效果
    Delphi里如何让程序锁定在桌面上,win+d都无法最小化
    php 之跨域上传图片
    delphi判断文件类型
    EmptyRecycle() 清空回收站
    delphi检查url是否有效的方法
    Explode TArray
    css设置中文字体(font-family:"黑体")后样式失效问题
    javascript-lessons
    课后作业2
  • 原文地址:https://www.cnblogs.com/wangmo/p/5997988.html
Copyright © 2011-2022 走看看