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