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

    此种方法省去的重复性的循环语句,用一个循环代替了所有

    Menu = {
        "北京":{
                "昌平":["沙河","辛庄","南口"],
                "朝阳":["太阳宫","孙河","管庄"],
                "海淀":["上地","西三旗","西二旗"]
              },
        "河南":{
                "郑州":["二七区","中原区","金水区"],
                "洛阳":["西工区","老城区","洛龙区"]
                },
        "河北":{
                "石家庄":["新华区","长安区","正定县"],
                "邯郸":["丛台区","复兴区","大名县"]
            },
        "广东":{
                "广州":["南沙区","花都区","番禹区"],
                "深圳":["龙岗区","罗湖区","盐田区"],
                "东莞":["南城区","东城区","万江区"]
        },
    }
    cur_menu = Menu
    parrent_menu = []
    while True:
        for keys in cur_menu:
            print(keys)
        choice = input("请选择>>>").strip()
        if len(choice) == 0:
            continue
        if choice in cur_menu:
            parrent_menu.append(cur_menu)
            cur_menu = cur_menu[choice]
        elif choice == "b":
            if parrent_menu:
                cur_menu = parrent_menu.pop()
        else:
            print("输入错误,请重新输入")
    

      

  • 相关阅读:
    (2015年郑州轻工业学院ACM校赛题) B迷宫
    (2015年郑州轻工业学院ACM校赛题) A 彩票
    POJ 1861 Network
    动态逆序对
    K大数查询
    Dynamic Rankings
    Cleaning
    Boxes
    P3601 签到题
    How many integers can you find
  • 原文地址:https://www.cnblogs.com/flash55/p/5807966.html
Copyright © 2011-2022 走看看