码迷,mamicode.com
首页 > 编程语言 > 详细

python day 1 homework 2

时间:2017-03-30 00:07:07      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:pytho   列表   知识点   ber   inpu   黑龙江   省份   span   UI   

多级菜单

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

标签:pytho   列表   知识点   ber   inpu   黑龙江   省份   span   UI   

原文地址:http://www.cnblogs.com/ccskun/p/6642444.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!