zoukankan      html  css  js  c++  java
  • 【Rollo的Python之路】Python:三级菜单练习

    menu = {
        "深圳":{
            "罗湖":{
                "罗湖火车站": {},
                "东门": {},
                "国贸": {},
                "布心": {},
            },
            "福田":{
                "香蜜湖": {},
                "华强北": {},
                "华强南": {},
                "市民中心": {},
            },
            "南山": {
                "南山中心城": {},
                "南头关": {},
                "华侨城": {},
            },
            "宝安": {
                "宝安中心": {},
                "西乡": {},
                "松岗": {},
            },
            "龙岗": {
                "龙岗中心城": {},
                "布吉": {},
                "坂田": {},
            },
        },
        "湖南":{
            "长沙": {
                "大学城区":{},
            },
            "衡阳":{
                "衡阳":{
                    "火车站":{},
                },
            },
            "郴州":{
                "北湖区": {},
                "苏仙区": {},
                "东湖区": {},
            },
    
        },
        "北京":{},
    }
    
    back_flag = False
    exit_flag = False
    while not back_flag and not exit_flag:
        for key in menu:
            print(key)
        choice = input("please choose the address:").strip()
        if choice in menu:
            while not back_flag and not exit_flag:
                for key2 in menu[choice]:
                    print(key2)
                choice2 = input("please choose the address").strip()
                if choice2 == "b":
                    back_flag = True
                if choice2 == "q":
                    exit_flag = True
                if choice2 in menu[choice]:
                    while not back_flag and not exit_flag:
                        for key3 in menu[choice][choice2]:
                            print(key3)
                        choice3 = input("please choose the address").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("please choose the address").strip()
                                print("last layer")
                                if choice4 == "b":
                                    back_flag = True
                                if choice4 == "q":
                                    exit_flag = True
                                    break
                            else:
                                back_flag = False
                    else:
                        back_flag = False
            else:
                back_flag = False
  • 相关阅读:
    基础编程练习题第一波
    TYVJ 1541 八数码
    NOIP 2014 寻找道路
    NOIP2014 解方程
    POJ 3213 矩阵乘法(优化)
    POJ 1523 Tarjan求割点
    POJ 3237 树链剖分+线段树
    SPOJ 375 树链剖分
    NOIP 2012 T2 国王游戏 (贪心+高精)
    POJ 1364 差分约束
  • 原文地址:https://www.cnblogs.com/rollost/p/10730271.html
Copyright © 2011-2022 走看看