作业需求如下

1、根据用户的输入打印相应的省、市、县的信息

2、每次只要用户输入b,则返回上一级菜单

3、每次只要用户输入q,则直接退出

4、用户输错需要有提示

homework_dict = {'内蒙古':{'呼和浩特':{'呼和浩特1':['a','b','c'],'呼和浩特2':['d','e','f'],'呼和浩特3':['h','i','j']},
                        '乌海': {'乌海1': ['A', 'B', 'C'], '乌海2': ['D', 'E', 'F'], '乌海3': ['H', 'I', 'J']}},
                 '黑龙江':{'哈尔滨':{'哈尔滨1':['k','l','m'],'哈尔滨2':['n','o','p'],'哈尔滨3':['q','r','s']},
                        '佳木斯': {'佳木斯1': ['K', 'I', 'M'], '佳木斯2': ['N', 'O', 'P'], '佳木斯3': ['Q', 'R', 'S']}},
                 '湖南':{'长沙':{'长沙1':['t','u','v'],'长沙2':['w','x','y'],'长沙3':['xx','yy','zz']},
                       '湘潭': {'湘潭1': ['T', 'U', 'V'], '湘潭2': ['W', 'X', 'Y'], '湘潭3': ['XX', 'YY', 'ZZ']}}}

while True:
    welcome = "欢迎来到大中华地区查询系统地"
    print(welcome.center(50,'-'))
    while True:
        for i, sheng in enumerate(homework_dict.keys()):
            print(i, sheng)
        option = input("which 【省】 do you want to come in?")
        if option == '0':
            while True:
                for i, shi in enumerate(homework_dict['内蒙古'].keys()):
                    print(i, shi)
                option = input("which 【市】 do you want to come in?")
                if option == '0':
                    while True:
                        for i, xian in enumerate(homework_dict['内蒙古']['呼和浩特'].keys()):
                            print(i, xian)
                        option = input("which 【县】 do you want to come in?")
                        if option == '0':
                            print("----------------------------------")
                            for i,xiang in enumerate(homework_dict['内蒙古']['呼和浩特']['呼和浩特1'] ):
                                print(i,xiang)
                            print("----------------------------------")
                            exit()
                        elif option == '1':
                            print("----------------------------------")
                            for i, xiang in enumerate(homework_dict['内蒙古']['呼和浩特']['呼和浩特2']):
                                print(i, xiang)
                            print("----------------------------------")
                            exit()
                        elif option == '2':
                            print("----------------------------------")
                            for i, xiang in enumerate(homework_dict['内蒙古']['呼和浩特']['呼和浩特3']):
                                print(i, xiang)
                            print("----------------------------------")
                            exit()
                        elif option == 'b':
                            break
                        elif option == 'q':
                            print("ByeBye")
                            exit()
                        else:
                            print("请输入正确的选项【0】【1】【2】【q】【r】:")
                            continue
                elif option == '1':
                    while True:
                        for i, xian in enumerate(homework_dict['内蒙古']['乌海'].keys()):
                            print(i, xian)
                        option = input("which 【县】 do you want to come in?")
                        if option == '0':
                            print("----------------------------------")
                            for i,xiang in enumerate(homework_dict['内蒙古']['乌海']['乌海1'] ):
                                print(i,xiang)
                            print("----------------------------------")
                            exit()
                        elif option == '1':
                            print("----------------------------------")
                            for i, xiang in enumerate(homework_dict['内蒙古']['乌海']['乌海2']):
                                print(i, xiang)
                            print("----------------------------------")
                            exit()
                        elif option == '2':
                            print("----------------------------------")
                            for i, xiang in enumerate(homework_dict['内蒙古']['乌海']['乌海3']):
                                print(i, xiang)
                            print("----------------------------------")
                            exit()
                        elif option == 'b':
                            break
                        elif option == 'q':
                            print("ByeBye")
                            exit()
                        else:
                            print("请输入正确的选项【0】【1】【2】【q】【r】:")
                            continue
                elif option == 'b':
                    break
                elif option == 'q':
                    print("ByeBye")
                    exit()
                else:
                    print("请输入正确的选项【0】【1】【2】【q】【r】:")
                    continue

        elif option == '1':
            while True:
                for i, shi in enumerate(homework_dict['黑龙江'].keys()):
                    print(i, shi)
                option = input("which 【市】 do you want to come in?")
                if option == '0':
                    while True:
                        for i, xian in enumerate(homework_dict['黑龙江']['哈尔滨'].keys()):
                            print(i, xian)
                        option = input("which 【县】 do you want to come in?")
                        if option == '0':
                            print("----------------------------------")
                            for i,xiang in enumerate(homework_dict['黑龙江']['哈尔滨']['哈尔滨1'] ):
                                print(i,xiang)
                            print("----------------------------------")
                            exit()
                        elif option == '1':
                            print("----------------------------------")
                            for i, xiang in enumerate(homework_dict['黑龙江']['哈尔滨']['哈尔滨2']):
                                print(i, xiang)
                            print("----------------------------------")
                            exit()
                        elif option == '2':
                            print("----------------------------------")
                            for i, xiang in enumerate(homework_dict['黑龙江']['哈尔滨']['哈尔滨3']):
                                print(i, xiang)
                            print("----------------------------------")
                            exit()
                        elif option == 'b':
                            break
                        elif option == 'q':
                            print("ByeBye")
                            exit()
                        else:
                            print("请输入正确的选项【0】【1】【2】【q】【r】:")
                            continue
                elif option == '1':
                    while True:
                        for i, xian in enumerate(homework_dict['黑龙江']['佳木斯'].keys()):
                            print(i, xian)
                        option = input("which 【县】 do you want to come in?")
                        if option == '0':
                            print("----------------------------------")
                            for i, xiang in enumerate(homework_dict['黑龙江']['佳木斯']['佳木斯1']):
                                print(i, xiang)
                            print("----------------------------------")
                            exit()
                        elif option == '1':
                            print("----------------------------------")
                            for i, xiang in enumerate(homework_dict['黑龙江']['佳木斯']['佳木斯2']):
                                print(i, xiang)
                            print("----------------------------------")
                            exit()
                        elif option == '2':
                            print("----------------------------------")
                            for i, xiang in enumerate(homework_dict['黑龙江']['佳木斯']['佳木斯3']):
                                print(i, xiang)
                            print("----------------------------------")
                            exit()
                        elif option == 'b':
                            break
                        elif option == 'q':
                            print("ByeBye")
                            exit()
                        else:
                            print("请输入正确的选项【0】【1】【2】【q】【r】:")
                            continue
                elif option == 'b':
                    break
                elif option == 'q':
                    print("ByeBye")
                    exit()
                else:
                    print("请输入正确的选项【0】【1】【2】【q】【r】:")
                    continue
        elif option == '2':
            while True:
                for i, shi in enumerate(homework_dict['湖南'].keys()):
                    print(i, shi)
                option = input("which 【市】 do you want to come in?")
                if option == '0':
                    while True:
                        for i, xian in enumerate(homework_dict['湖南']['长沙'].keys()):
                            print(i, xian)
                        option = input("which 【县】 do you want to come in?")
                        if option == '0':
                            print("----------------------------------")
                            for i, xiang in enumerate(homework_dict['湖南']['长沙']['长沙1']):
                                print(i, xiang)
                            print("----------------------------------")
                            exit()
                        elif option == '1':
                            print("----------------------------------")
                            for i, xiang in enumerate(homework_dict['湖南']['长沙']['长沙2']):
                                print(i, xiang)
                            print("----------------------------------")
                            exit()
                        elif option == '2':
                            print("----------------------------------")
                            for i, xiang in enumerate(homework_dict['湖南']['长沙']['长沙3']):
                                print(i, xiang)
                            print("----------------------------------")
                            exit()
                        elif option == 'b':
                            break
                        elif option == 'q':
                            print("ByeBye")
                            exit()
                        else:
                            print("请输入正确的选项【0】【1】【2】【q】【r】:")
                            continue
                elif option == '1':
                    while True:
                        for i, xian in enumerate(homework_dict['湖南']['湘潭'].keys()):
                            print(i, xian)
                        option = input("which 【县】 do you want to come in?")
                        if option == '0':
                            print("----------------------------------")
                            for i, xiang in enumerate(homework_dict['湖南']['湘潭']['湘潭1']):
                                print(i, xiang)
                            print("----------------------------------")
                            exit()
                        elif option == '1':
                            print("----------------------------------")
                            for i, xiang in enumerate(homework_dict['湖南']['湘潭']['湘潭2']):
                                print(i, xiang)
                            print("----------------------------------")
                            exit()
                        elif option == '2':
                            print("----------------------------------")
                            for i, xiang in enumerate(homework_dict['湖南']['湘潭']['湘潭3']):
                                print(i, xiang)
                            print("----------------------------------")
                            exit()
                        elif option == 'b':
                            break
                        elif option == 'q':
                            print("ByeBye")
                            exit()
                        else:
                            print("请输入正确的选项【0】【1】【2】【q】【r】:")
                            continue
                elif option == 'b':
                    break
                elif option == 'q':
                    print("ByeBye")
                    exit()
                else:
                    print("请输入正确的选项【0】【1】【2】【q】【r】:")
                    continue
        elif option == 'b':
            break
        elif option == 'q':
            print("ByeBye")
            exit()
        else:
            print("请输入正确的选项【0】【1】【2】【q】【r】:")
            continue

  

posted on 2017-04-18 17:52  bainianminguo  阅读(294)  评论(0编辑  收藏  举报