Go Python Dictionary implementation level three menu

Source: Internet
Author: User

Python Dictionary implementation level three menu

Original: https://www.cnblogs.com/pyramid1001/p/5803294.html

 1 ################################################ 2 # Task Name: Level Three menu # 3 # Description: Print province, city, County level Three Menu # 4 # can return to the previous level # 5 # can quit the program at any time # 6 #------ ----------------------------------------# 7 # author:oliver Lee # 8 ############################ #################### 9 zone = {11 ' shandong ': {12 ' qingdao ': [' Quartet ', ' Huangdao ', ' Laoshan ', ' Lichang ', ' Chengyang '],13 ' Jinan ': [' Licheng ', ' Huaiyin ' , ' high-tech ', ' Evergreen ', ' Zhangqiu '],14 ' Yantai ': [' Longkou ', ' Laishan ', ' muping ', ' Penglai ', ' Zhaoyuan ']15},16 ' Jiangsu ': {17 ' Suzhou ': [' Canglang ', ' Xiangcheng ', ' Pingjiang ', ' Wuzhong ', ' Kunshan '],18 ' nanjing ': [' baixia ', ' Qinhuai ', ' Pukou ', ' qixia ', ' Jiangning '],19 ' Wuxi ': [' Chongan ', ' Nanchang ', ' Beitang ', ' Xishan ', ' Jiangyin ']20},21 ' Zhejiang ': {2 2 ' Hangzhou ': [' West Lake ', ' Jianggan ', ' Downtown ', ' Uptown ', ' Binjiang '],23 ' ningbo ': [' Haishu ', ' jiangdong ', ' Jiangbei ', ' Zhenhai ', ' Yuyao '],24 ' Wenzhou ': [' Lucheng ', ' Longwan ', ' Leqing ' , ' Ruian ', ' Yongjia ']25},26 ' Anhui ': {27 ' Hefei ': [' Shushan ', ' Luyang ', ' Baohe ', ' open ', ' new station '],28 ' Wuhu ': [' Lake Lake ', ' Jiujiang ', ' inaction ', ' Sanshan ', ' nanling ' '],29 ' Bengbu ': [' clamMountain ', ' Dragon Lake ', ' Huai ', ' Huaiyuan ', ' Guzhen ']30},31 ' Guangdong ': {32 ' Shenzhen ': [' Luohu ', ' Futian ', ' Nanshan ', ' Baoan ', ' Phuket '],33 ' Guangzhou ': [' Tianhe ', ' Zhuhai ', ' Yuexiu ', ' Baiyun ', ' Huangpu '],34 ' Dongguan ': [' Guancheng ', ' Changan ', ' humen ', ' Wanjiang ', ' Big Lang ']35}36}37 province_list = List (Zone.keys ()) #         Province List # flag = False39 # Flag1 = False40 while true:41 print ("Province". Center ("* ')"). Print (Province_list.index (i) +1,i) #打印省列表44 pro_id = input ("Please enter the province number, or enter Q (quit) exit:") #省ID45 if pro_id.is Digit (): pro_id = Int (pro_id) if pro_id > 0 and pro_id <= len (province_list): Pro_ Name = Province_list[pro_id-1] #根据省ID获取省名称49 city_list = List (Zone[pro_name].keys ()) #根据省名称获取对应的值, from the new dictionary                      Get key, which is the city list, while true:51 print ("City". Center (+, ' * ')) for the V in city_list:53 Print (City_list.index (v) +1,v) #打印市列表54 city_id = input ("Please enter the city number, or enter B (back) to return to the parent menu      , or enter Q (quit) to exit: ") 55           If City_id.isdigit (): city_id = Int (city_id) if city_id > 0 and                         city_id <= Len (city_list): City_name = city_list[city_id-1] #根据市ID获取市名称59                             Town_list = Zone[pro_name][city_name] #根据省名称获取对应的值, gets the value from the new dictionary, which is the county list while true:61                                 Print ("county"). Center ((s), ' * ') "for J in town_list:63 Print (Town_list.index (j) +1,j) Back_or_quit = input ("Input B (back) returns to the parent menu, or input Q (quit) exits: ") If back_or_quit = = ' B ': Break #终止此层while Loop, jumps to the previous layer while.                                elif Back_or_quit = = ' Q ': Flag1 = True69 # break #根据标志位结束程序.   + exit () else:72                              Print ("Input illegal! ") else:74 print (" Number%d does not exist.)                     "%city_id" elif city_id = = ' B ': break77 elif city_id = = ' Q ': 78                     # flag = True79 # break80 exit () Bayi else:82 Print ("Input illegal!") If flag1:84 # break85 else:86 print ("Number%d does not exist. "%pro_id" elif pro_id = = ' Q ': break89 else:90 print ("Input illegal!") # if flag or flag1:92 # break

Go Python Dictionary implementation level three menu

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.