多级菜单

# *_*coding:utf-8 *_*


# 使用字典保存省份、市、县列表
# 这是一个多级的字典,可以通过for查询每一个级别的信息,级别:省份、市、区

_country_dict = {
    "北京":{
        "昌平":{
            "沙河":{"oldboy","test"},
            "天通苑":{"链家地产","我爱我家"}
        },
        "朝阳":{
            "望京":{"奔驰","陌陌"},
            "国贸":{"CICC","HP"},
            "东直门":{"Advent","飞信"},
        },
        "海淀":{},
    },
    '山东':{
        "德州":{},
        "青岛":{},
        "济南":{},
    },
    "广东":{
        "东莞":{},
        "常熟":{},
        "佛山":{},
    },
}


exit_flag = False
while not exit_flag:
    for i in _country_dict:
        print(i)
    choice = input("请选择省份>>>>>:")
    if choice in _country_dict:
        while not exit_flag:
            for i2 in _country_dict[choice]:
                print("\t", i2)
            choice2 = input("请输入城市>>>>>>:")
            if choice2 in _country_dict[choice]:
                while not exit_flag:
                    for i3 in _country_dict[choice][choice2]:
                        print("\t\t", i3)
                    choice3 = input("请输入市区>>>>:")
                    if choice3 in _country_dict[choice][choice2]:
                        while not exit_flag:
                            for i4 in _country_dict[choice][choice2][choice3]:
                                print("\t\t\t",i4)
                            choice4 = input("返回或退出:b or q")
                            if choice4 =="b":
                                pass
                            elif choice4 =="q":
                                exit_flag =True
                    elif choice3 == "b":
                        break
                    elif choice3 == "q":
                        exit_flag=True
            elif choice2 == "b":
                break
            elif choice2 == "q":
                exit_flag= True
    elif choice == "q":
        exit_flag=True

 

转载于:https://www.cnblogs.com/hamao/p/11040906.html

你可能感兴趣的:(多级菜单)