• python-三级菜单


    第一种方法:

    # _Author:huang
    # date: 2017/11/29

    menu = {
    '河南': {
    '郑州': {
    '金水区': {
    '东风路': {},
    '北三环': {},
    '明基路': {}
    },
    },
    '南阳': {
    '淅川县': {},
    '西峡县': {},
    '方程': {},
    },
    },
    '江苏': {
    '南京': {
    '鼓楼': {},
    '栖霞区': {},
    '下关区': {}
    },
    '苏州': {
    '城区': {},
    '苏州园林': {}
    }
    },
    '北京': {
    '昌平区': {
    'sohu': {},
    'sogo': {}
    },
    '昭阳区': {
    '360': {},
    'google': {}
    }
    }
    }

    current_layer = menu

    parent_layers = []

    while True:
    for key in current_layer:
    print(key)
    choice = input(">>>:").strip()
    if len(choice) == 0:
    continue
    if choice in current_layer:
    parent_layers.append(current_layer)
    current_layer = current_layer[choice]

    elif choice == 'b':
    if parent_layers:
    current_layer = parent_layers.pop()
    else:
    print("无此地名")




    第二种方法:
    # _Author:huang
    # date: 2017/11/28

    menu = {
    '北京': {
    '朝阳': {
    '国贸': {
    'CICC': {},
    'HP': {},
    '渣打一行': {}
    }
    },
    '望京': {
    '陌陌': {},
    '奔驰': {},
    '360': {}
    },
    '三里屯': {
    '优衣库': {},
    'apple': {}
    },
    '昌平': {
    '天通苑': {
    '链家': {},
    '我爱我家': {}
    },
    '回龙观': {},
    },
    '海淀': {
    '五道口': {
    '谷歌': {},
    '网易': {},
    'sohu': {},
    'sogo': {},
    '快手': {},
    },
    '中关村': {
    'youku': {},
    'Iqiyi': {},
    "汽车之家": {},
    "新东方": {},
    'QQ': {}
    }
    }
    },
    '上海': {
    '浦东': {
    '陆家嘴': {
    'CICC': {},
    '高盛': {},
    '摩根': {}
    },
    '外滩': {},
    },
    '闵行': {},
    '静安': {}
    },

    '山东': {
    '济南': {},
    '青岛': {},
    '德州': {
    '乐陵': {
    '丁坞镇': {},
    '城区': {}
    },
    '平原县': {}
    }
    }
    }
    back_flag = False
    exit_flag = False
    while not back_flag and not exit_flag:
    for key in menu:
    print(key) # 打印第一层代码
    choice = input(">>:").strip()
    if choice == 'b':
    back_flag = True
    if choice == 'q':
    exit_flag = True
    if choice in menu: # 判断是否在第一层
    while not back_flag and not exit_flag: #让程序停在第二层
    for key2 in menu[choice]:
    print(key2) # 打印第二层
    choice2 = input("2>>:").strip()
    if choice2 == 'b':
    back_flag = True
    if choice2 == 'q':
    exit_flag = True
    if choice2 in menu[choice]:
    for key3 in menu[choice][choice2]:
    print(key3)
    choice3 = input("3>>:").strip()
    if choice3 == 'b':
    back_flag = True
    if choice3 == 'q':
    exit_flag = True
    if choice3 in menu[choice][choice2]:
    while not back_flag and not exit_flag:
    for key4 in menu[choice][choice2][choice3]:
    print(key4)
    choice4 = input("4>>:").strip()
    print("last lever")
    if choice4 == 'b':
    back_flag = True
    if choice4 == 'q':
    exit_flag = True
    else:
    back_flag = False

    else:
    back_flag = False

    else:
    back_flag = False

  • 相关阅读:
    C# QRCode、DataMatrix和其他条形码的生成和解码软件
    windows系统 安装MongoDB 32位
    ubuntu下创建c语言程序之hello world
    ueditor 添加微软雅黑字体 异常“从客户端中检测到有潜在危险的 request.form值”,解决
    asp.net ueditor 图片上传路径问题解决
    C# winform线程的使用 制作提醒休息小程序(长时间计算机工作者必备)
    jquery.qrcode和jqprint的联合使用,实现html生成二维码并打印(中文也ok)
    javascript陷阱之in语句
    谈谈Python的深拷贝和浅拷贝
    Flask开启多线程、多进程
  • 原文地址:https://www.cnblogs.com/1510152012huang/p/7922158.html
Copyright © 2020-2023  润新知