#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.......")
三级菜单 python
最新推荐文章于 2022-12-16 14:03:37 发布