Three menu on tall version

_ * _ Coding #: UTF-8 _ * _ 
# Author: Wang Dian-yuan
# Date: 2019/12/15
'' '
three new menu functional requirements
1. The need to save the file to the local content
2. Users can regional content CRUD
'' '
the MENU = {
' Shanghai ': {
' Minhang District ': {
' old Minhang ': {
' Zizhu Science Park ': {},
' Shanghai Jiao Tong University ': {}
}
' new Minhang ': {
'River town': {},
'Caohejing': {}
}
},
'Huangpu District': {
'Bund': {
'Oriental Pearl': {},
'Nanjing pedestrian Street': {},
'Yuyuan': {}
},
'Architecture': {
'People's Square': {},
'Theater': {}
}
}
},
'Shenzhen': {
'Futian District': {
'Huaqiang North': {
'Huaqiang Electronic City': {},
'SEG Electronic City': {},
},
'walking Street': {
'East Gate walking Street': {},
'lychee Park': {}
}
},
'Nanshan District': {
'Science Park': {
'Nanshan Science and Technology Park': {}
' Xili Technology Park ': {}
}
' phone garden ': {
' Cool Technology Park ': {},
' OPPO Technology Park ': {}
}
},
},
}
Open with ( 'three_level_menu', 'R & lt', encoding = 'UTF8') AS menu_read:
Zone = the eval (. menu_read.read () Strip ())
MSG = '' 'Enter Area * ******* ******
input b return to the previous
input q to quit
************************************************************ '' '
current_layer = Zone
parent_layers = []
user_enter_quit = False
the while not user_enter_quit:
Print (msg)
for Key in current_layer:
Print (Key)
user_enter the INPUT = ( "Please the INPUT:")
IF user_enter in current_layer:
parent_layers.append (current_layer) # each layer corresponds to the current dictionary added to the list in
current_layer = current_layer [user_enter] # dictionary assigned next layer the current layer
elif user_enter.lower () == 'b'and parent_layers != []:
current_layer = parent_layers.pop () # default delete the last element of the list, and returns the element value. Does not increase the length of the list using the pop
elif user_enter.lower () == 'Q':
current_layer = parent_layers.pop (0)
user_enter_quit = True
elif user_enter Not in current_layer: # If user input is not in the dictionary, the user is inputted as key to add a new dictionary
IF user_enter == 'MOD':
original_zone the iNPUT = ( 'Please enter the modified region:')
mod_zone the iNPUT = ( 'Please enter content:')
current_layer [mod_zone] = current_layer [original_zone]
current_layer .pop (original_zone)
elif user_enter == 'REM':
rem_enter the iNPUT = ( 'Please enter the area to be deleted:')
current_layer.

add_enter = input ( 'I'm sorry, no such region, please re-enter Add Region:')
current_layer [add_enter] = {#} After writing dictionary user input, the process proceeds to the next level, the user continues to enter the next prompt location
# print (current_layer [user_enter])
the else:
Print ( 'last layer')
the else:
Print ( '! Please Enter Again')
with Open ( 'three_level_menu', 'W', encoding = 'UTF8') AS menu_write:
menu_write.write (str (current_layer) .strip () )

Guess you like

Origin www.cnblogs.com/python-beginner/p/12065398.html