三级菜单 python

#Author craneliu
#三级菜单
#(1)可依次选择进入各子菜单
#(2)每个子菜单可以逐级返回到一级菜单
#(3)每个子菜单可以直接退出程序


pro_city_dist={
    "广东":
       {
           "广州市":{
              "越秀区":{},
              "荔湾区":{},
              "白云区":{}
            },
       "深圳市":
            {
             "深圳越秀区":{},
             "深圳荔湾区":{},
             "深圳白云区":{}
             },
       "佛山市":
             {
             "佛山市越秀区":{},
             "佛山市荔湾区":{},
             "佛山市白云区":{}
              }
       },
   "广西":
       {
        "南宁市":
            {
             "南宁市越秀区":{},
             "南宁市荔湾区":{},
             "南宁市白云区":{}
            },
        "柳州市":
            {"柳州市越秀区":{},
             "柳州市荔湾区":{},
             "柳州市白云区":{}
             },
        "桂林市":
            {
             "桂林市越秀区":{},
             "桂林市荔湾区":{},
             "桂林市白云区":{}
             },
        },
   "湖南":
       {
        "长沙市":
            {
             "长沙市越秀区":{},
             "长沙市荔湾区":{},
             "长沙市白云区":{}
             },
        "株洲市":
            {
             "株洲市越秀区":{},
             "株洲市荔湾区":{},
             "株洲市白云区":{}
             },
        "湘潭市":
            {
             "湘潭市越秀区":{},
             "湘潭市荔湾区":{},
             "湘潭市白云区":{}
             }
         }
}

cycle_flag=True
while cycle_flag:
    #显示选择菜单栏
    show_menu = input("Would you like to display this menu ? Y/N:")
    if show_menu == 'Y' or show_menu == "y":
        print("Welcome ! We will show you the pronvince list as below.")
        while cycle_flag:
            prov_sav={}
            for index, item in enumerate(pro_city_dist):
                print(index, item)
                prov_sav[index]=item     #保存省名称和序号的对应(后面的雷同)
            pronvine_choice = input(  ####进入市菜单
                ">>>>>>What's your choice ?\n"
                ">>>>>>Input nmber for a pronvince's city\n"
                ">>>>>>Q(uit) for exitting the programm\n"
                ">>>>>>R(eturn) for backup to  the top menu\n"
                ">>>>>>Your choice ?:"
            )
            if pronvine_choice == 'q' or pronvine_choice == 'Q':
                print("OK ! This programm will exit right now from province menu .....")
                cycle_flag = False
            elif pronvine_choice.isdigit():
                pronvine_choice = int(pronvine_choice)
                if pronvine_choice >= 0 and pronvine_choice < len(pro_city_dist):
                    while cycle_flag:
                        city_save={}
                        for index, item in enumerate(pro_city_dist[prov_sav[pronvine_choice]]):
                            print(index, item)
                            city_save[index]=item
                        city_choice = input(  ####进入区菜单
                            ">>>>>>What's your choice ?\n"
                            ">>>>>>Input nmber for a city's area\n"
                            ">>>>>>Q(uit) for exitting the programm\n"
                            ">>>>>>R(eturn) for backup to  the pronvine menu\n"
                            ">>>>>>Your choice ?:"
                        )
                        if city_choice == 'Q' or city_choice == 'q':
                            print("OK ! This programm will exit right now from city menu.....")
                            cycle_flag = False
                        elif city_choice == 'R' or city_choice == 'r':
                            break
                        elif city_choice.isdigit():
                            city_choice = int(city_choice)
                            while cycle_flag:
                                for index, item in enumerate(pro_city_dist[prov_sav[pronvine_choice]][city_save[city_choice]]):
                                    print(index, item)
                                area_choice = input(">>>>>>What's your choce ?\n"
                                                    ">>>>>>Q(uit) for exitting the programm\n"
                                                    ">>>>>>R(eturn) for backup to  the city menu\n"
                                                    ">>>>>>Your choice ?:"
                                                    )
                                if area_choice == 'q' or area_choice == 'Q':
                                    cycle_flag = False
                                elif area_choice == 'R' or area_choice == 'r':
                                    break
                                else:
                                    print("Sorry ! Invalid choice!Try again ,please !")
                        else:
                            print("Sorry ! Invalid choice!Try again ,please !")
                else:
                    print("Sorry ! Invalid choice!Try again ,please !")
            elif pronvine_choice == 'R' or pronvine_choice == 'r':
                break
            else:
                print("Sorry ! Invalid choice!Try again ,please !")

    elif show_menu == 'N' or show_menu == 'n':
        print("OK ! This programm will exit right now from top menu")
        break
    else:
        print("Sorry ! invalid option.......")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值