Python's Multi-layer menu (1th day)

Source: Internet
Author: User

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)

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.