Implemented in Python-level menu. Requirements: 1 Print provincial and county levels; 2 to return to the previous level; 3 can exit the program at any time....

Code:

MENU = { 
'Beijing': {
'sun': {
'Uniqlo': {
'A': {},
'B': {},
},
'chain of home': {
'C': {},
'D': {}
}
}
'wangjing': {
'E': {},
'F.': {}
},
'Haidian': {
'G': {},
'H': {}
}
}
'Shanghai': {
'Pudong': {
'Lujiazui': {
'the CICC': {},
'Morgan ": {}
},
" Bund ": {}
},
'Air out': {},
'Jing ": {}
},
" Sichuan': {
'Chengdu': {
'Wuhou': {},
'Pi': {},
'Chunxi': { }
}
'Mianyang': {},
'guangyuan': {
'X-': {
'the X1': {},
'an X2': {}
},
'the Y': {}
}
}

}
current_Layr = MENU # implemented dynamic cycle
parent_Layrs = [] # saved all parent, the last element is always a parent on
the while True:
for Key in current_Layr:
Print (Key)
Choice = the INPUT ( '>>>:').strip()
if len(choice)==0:continue
if choice in current_Layr:
# Before one parent_Layrs.append (current_Layr) at entry, the current layer is added to the list, the next time
# b when the user selects, one can directly pick up the last value in the list of
current_Layr = current_Layr [choice] # enter sublayer
elif Choice == 'B':
IF parent_Layrs: # the non-empty list will be true
current_Layr = parent_Layrs.pop () # remove the last value in the list, because it is the parent of the current layer
the else:
Print ( 'without this ')
operating results




Guess you like

Origin www.cnblogs.com/fzw1995/p/11318292.html