Python: For beginners of Level 3 menus,

Source: Internet
Author: User

Python: For beginners of Level 3 menus,

# Implement three levels of menus at the provincial and municipal levels #! /User/bin/env pythoncitys = {"Guangdong Province": {"Guangzhou City": ["Panyu District", "Tianhe District", "Baiyun district"], "Shenzhen City ": ["Nanshan District", "Baoan District", "Luohu District"], "Huizhou City": ["Huidong", "huiyang", "Freshwater"]}, "Hunan Province ": {"Wuhan": ["Yellow Crane Tower", "hubu Lane", "Donghu"], "Yichang": ["Three Gorges Dam", "Gezhouba", "Xixia"], "Enshi": ["shennongxi", "Enshi Tusi City", "Daughter City"]}, "Hebei Province": {"Beijing": ["Forbidden City", "Tiananmen Square ", "Badaling"], "Taiyuan": ["Jinci", "Liuxiang", "zhudian"], "Shijiazhuang": ["Zhao Zhou Bridge", "Longxing Temple ", "xibo"]} print (citys ["Guangdong Province"] ["Guangzhou City"]) while True: for a in citys. keys (): print (a) city = input ("enter the city you want to know:") if city in citys and city = "Guangdong Province ": for B in citys [city]. keys (): print (B) area = input ("Enter the region you want to know:") if area in citys [city] and area = "Guangzhou city ": for B in citys [city] [area]: print (B) turn = input ("press any key to return the previous layer, press q to exit the program") if turn = "q ": break else: continue

The above code is a simple and cumbersome one, and the code behind it will be repeated all the time, so it is not written, followed by the code that comes with my video, and I am also attached, more complete than what I wrote

Data = {'beijing': {"Changping": {"shahe": ["oldboy", "test"], "tiantongyuan": ["chain home property ", "I love my family"]}, "Chaoyang": {"Wangjing": ["Benz", "momo"], "International trade": {"CICC", "HP "}, "Dongzhimen": {"Advent", "Feixin" },}, "Haidian" :{},}, 'shandong ': {"Dezhou ":{}, "Qingdao" :{}, "Jinan" :{}}, 'guangdong ': {"Dongguan" :{}, "Changshu" :{}, "Foshan ": {},}}exit_flag = Falsewhile not exit_flag: for I in data: print (I) choice = input ("select to enter 1 >:") if choice in data: while not exit_flag: for i2 in data [choice]: print ("\ t", i2) choice2 = input ("select to enter 2> :") if choice2 in data [choice]: while not exit_flag: for i3 in data [choice] [choice2]: print ("\ t", i3) choice3 = input ("select to enter 3 >>:") if choice3 in data [choice] [choice2]: for i4 in data [choice] [choice2] [choice3]: print ("\ t", i4) choice4 = input ("last layer, return by B>:") if choice4 = "B ": pass elif choice4 = "q": exit_flag = True if choice3 = "B": break elif choice3 = "q": exit_flag = True if choice2 = "B ": break elif choice2 = "q": exit_flag = True

 

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.