Job 2: Multilevel menu
Level three Menu
You can select to go to each submenu in turn
New knowledge points required: list, dictionary
1. Flowchart
2, login interface, enter the corresponding index
#!/usr/bin/env python3#-*-coding:utf-8-*-# version:python3.5.0# Initialize city information city_dict = {' Guangzhou ': {' Tianhe ': [' Tianhe Stadium ', ' Kinsan '], ' Yuexiu ': [' Yuexiu Park ', ' Guangxiao Temple '], ' panyu ': [' Chimelong Happy World ', ' Doctor Mountain ']}, ' Shenzhen ': {' Fukuda ': [' Lotus Mountain ', ' seg '] , ' Longhua ': [' Wonsan Park ', ' Dragon City Plaza '], ' Nanshan ': [' Window of the world ', ' Happy Valley ']}, ' Foshan ': {' Shancheng ': [' Liangyuan ', ' hole ' Temple '], ' Nanhai ': [' Thousand Lights Lake ', ' Southern Taoyuan '], ' shunde ': [' Ching Fai Yuen ', ' Xishan temple ']}}# Create city Index list city_index = [(Index, KE Y) for index, key in enumerate (city_dict)]city_index.append ((Len (city_index), ' exit ') # Add exit option while True:print (' Welcome to City Letter ") Print ('--------------------------------') for I in City_index: # Print City Index menu for J in I:print (j, end= ") print (') get_city = input (' Please select the index number of the query: ') if not Get_city.isdigit (): Print (' Enter a numeric index number. ') continue elif int (get_city) >= len (city_index): # The input index number is greater than or equal to the city index number length print (' Input number is too large, please re-enter. ') continue elif int (get_city) = = Len (city_index)-1: # The maximum index number for the exit program corresponds to the index number print (' Welcome to login again, bye bye! ') Break else:choose_city = City_index[int (get_city)][1] # Gets the selected city name # The index list of the creation area Area_index = [(i Ndex, key) for index, key in enumerate (City_dict[choose_city])] Area_index.append ((Len (area_index), ' return ')) # Increase return on One-level menu option while True:for i in Area_index: # Print Select the city's district index menu for J in I: Print (J, end= ") print (') Get_area = input (' Please select the index number of the query: ') if not get_area.isdigit (): Print (' Please enter a numeric index number. ') continue elif int (get_area) >= len (area_index): # The input index number is greater than the city index number print (' Input The number is too large, please enter it again. ') continue elif int (get_area) = = Len (area_index)-1: # The largest index number is the index number of the parent menu print ( ' Return to the previous level menu. ') Break Else:choose_area = Area_index[int (Get_area)][1] # Gets the name of the selectorPrint (City_dict[choose_city][choose_area]) # Prints information for this area print ('--------------------------------')
Python's Multi-layer menu (1th day)