python day 1 homework 2

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python day 1 homework 2相关的知识,希望对你有一定的参考价值。

多级菜单

1 三级菜单

2 可依次选择进入各子菜单

3 所需新知识点,列表,字典

province_info = {"1":{"name":"黑龙江",
                      "city":{"1":{"name":"哈尔滨","area":"道里区、南岗区、道外区、平房区、松北区、香坊区、呼兰区、阿城区、双城区"},
                              "2":{"name":"齐齐哈尔市","area":"龙沙区、建华区、铁锋区、富拉尔基区、昂昂溪区、碾子山区、梅里斯达斡尔族区"},
                              "3":{"name":"鸡西市","area":"鸡冠区、恒山区、滴道区、梨树区、城子河区、麻山区、鸡东县、虎林市、密山市"},
                              "9":{"name":"返回"},
                              "0":{"name":"退出"}}},
                 "2":{"name":"吉林",
                      "city":{"1":{"name":"长春", "area":"朝阳、南关、宽城、绿园、二道、双阳"},
                              "2":{"name":"吉林", "area":"昌邑区、船营区、龙潭区、丰满区"},
                              "9": {"name": "返回"},
                              "0": {"name": "退出"}}},
                 "3":{"name":"辽宁",
                      "city":{"1":{"name":"沈阳", "area":"沈河区,和平去,大东区,皇沽区,铁西新区"},
                              "2":{"name":"铁岭", "area":"开发区、新城区、银州区、清河区"},
                              "9": {"name": "返回"},
                              "0": {"name": "退出"}}}}

menuinfo = """
1 黑龙江省
2 吉林省
3 辽宁省
0 退出"""

province = 1
city = 1
area = 1
while province :
    city = 1
    area = 1
    print(menuinfo)
    province_number = input("请输入要查看的省份编号:")
    if province_number=="0" :
        print("你选择了退出,再见!")
        break
    if province_number not in province_info.keys() :
        print("无此省份编号,请输入以下省份编号或选【0】退出。")
        continue
    while city :
        area = 1
        #获取省份下的城市名称
        d_citys = province_info.get(province_number);
        while area:
            print("\t{name}有如下城市:".format(name=d_citys.get("name")))
            for k, value in d_citys.get("city").items():
                print("\t\t{number} {city}".format(number=k,city=value.get("name")))
            city_number = input("\t\t请输入要查看的城市的编号:")
            if city_number == "0":
                print("你选择了退出,再见!")
                province = 0
                city = 0
                break;
            if city_number == "9":
                city = 0
                area = 0
                break
            if city_number not in d_citys.get("city").keys():
                print("无此城市编号,请输入以下城市编号或选【9】返回,【0】退出。")
                continue
            print("\t\t\t" + d_citys.get("city").get(city_number).get("area"))

 

以上是关于python day 1 homework 2的主要内容,如果未能解决你的问题,请参考以下文章

day7_homework

day01-homework_购物车程序

Python实战作业-day5

DAY1_homework

day3 homework

Day05_homework