Three-level menu Lite

# _ * _ Coding: UTF-8 _ * _ 
# Author: Wang Dian-yuan
# Date: 2019/12/14
the MENU = {
'Shanghai': {
'Minhang District': {
'old Minhang': {
'Zizhu Science Park': {} ,
'Shanghai Jiao Tong University': {}
}
'new Minhang': {
'River town': {},
'Caohejing': {}
}
},
'Huangpu District': {
'Bund': {
'Pearl of the Orient ': {},
' Nanjing pedestrian Street ': {},
' Yuyuan ': {}
},
' building ': {
' 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 Science Park ': {},
' OPPO Technology Park ':} {,
},
},
},
}
MSG =' ''******* ******* Please enter the area
input b Return to the previous
enter q to quit
********************************************************** ' ''
current_layer = MENU
= 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) every current # layer corresponds to the additional dictionary list
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 Removes the last element in the list, and returns the element value. Does not increase the length of the list using the pop
elif user_enter.lower () == 'Q':
user_enter_quit = True
the else:
( '! Please Enter Again') Print

Guess you like

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