Provincial/municipal level-3 menu query applet,
Note:
1. the user selects the corresponding option according to the program prompt. If the input is invalid, the user will be prompted to re-enter the option. Select q to exit the program.
2. Go to the Level 3 menu. Only the exit option and the back-to-level menu option are available.
3. The current program can print at most to the Level 3 directory, and display the level 1 menu
#! /Usr/bin/env python
# Coding: UTF-8
# Auto: Panwenbin
# Function:
Menu = ['beijing', 'shanghai']
Bei_jing = [['daxing ', ['daxing yi', 'daxing 2'], ['changping', ['changping yi', 'changping 2']
Shang_hai = [['whampoa ', ['whampoa yi', 'whampoa 2'], ['xuhui yi', ['xuhui yi', 'xuhui 2']
######################################## ######################################## ######################################
Print (
'''
------------------------------------
+
+
+
+ \ 033 [31 m welcome to the nationwide Query System \ 033 [0 m
+
+
+
------------------------------------
'''
)
######################################## ######################################## ########################################
Def showzone (zonename, sheng_name1, shi_name1): # define the function to implement the function
While True:
For I in range (len (zonename): # obtain the number of word areas in the first-level area selected by the user
Print ('% d: % s' % (I, zonename [I] [0]) # print the name of level 1 subarea
Shi_name = input (''' select the city or district to query:
Press B to return to the upper menu, and press q to exit the query.
''')
If shi_name.isdigit (): # judge whether the user input is a number. if yes, convert it to the int type.
Shi_name = int (shi_name)
If shi_name <len (zonename) and shi_name = 0: # determine whether the number entered by the user is greater than the number in the first-level area, and determine the option selected by the user
For I in range (len (zonename [sheng_name] [shi_name]): # Use the shape parameter zonename to obtain the user's selection. Based on the sheng_name and shi_name values entered by the user, the values are different based on the user input, print different regions
Print ('% d: % s' % (I, zonename [sheng_name] [shi_name1] [I-1])
Elif shi_name <len (zonename) and shi_name = 1:
For I in range (len (zonename [sheng_name] [shi_name]):
Print ('% d: % s' % (I, zonename [sheng_name1] [shi_name] [I])
Elif shi_name = 'q': # determine whether the user chooses to exit
Exit ()
Elif shi_name = 'B': # determines whether the user chooses to return to the upper menu
Continue
Else:
Print ('input error, please reselect. \ N' # When the user enters a value other than the given value, the user is prompted to re-enter
'Press B to return to the upper menu and press q to exit the query :')
Con_or_brk = input ('query has ended. Press B to return to the upper-level menu and press q to exit the query: ') # In the third-level menu, you cannot continue to select the next menu. operations after obtaining the user are performed.
If con_or_brk = 'q': # determine whether the user chooses to exit
Exit ()
Elif con_or_brk = 'B': # determines whether the user chooses to return to the upper menu
Continue
Else:
Print ('input error, please reselect. \ N'
'Return to the upper menu by 'B' and exit the query by 'q: ') # When the user enters a value other than the specified value, the system prompts you to re-enter the value.
######################################## ######################################## ########################################
While True:
For I in range (len (menu )):
Print ('% d: % s' % (I, menu [I]) # print the first-level menu directory
Sheng_name = input ('select the province or municipality to query and exit the program by q :')
If sheng_name.isdigit () and int (sheng_name) <len (menu): # judge whether the number entered by the user is smaller than the number of the current region. if yes, convert it to the int type.
Sheng_name = int (sheng_name)
Elif sheng_name = 'q ':
Break
Else:
Print ('input error, please reselect ')
Continue
If sheng_name <len (menu) and sheng_name = 0: # determine whether the selected level-1 region is valid and is equal to the corresponding value, and perform the corresponding operation
Showzone (bei_jing, 1, 1)
Elif sheng_name <len (menu) and sheng_name = 1:
Showzone (shang_hai, 0, 1)