Requirements:
can select to enter the sub-menu
can layer on the back retreated from any layer
can be from any one to exit the program
required new knowledge: lists, dictionaries
Data structures:
MENU = {
'Beijing': {
'Haidian': {
'Wudaokou': {
'SOHO': {},
'YORK': {},
"Google": {}
},
'Zhongguancun': {
'love Fantastic Art ': {},
' car home ': {},
' All Time Youku ': {}
}
' on the ground ': {
' Baidu ': {}
}
},
' Changping ': {
' River ' : {
'old boy': {},
'Northern': {}
},
'Tiantongyuan': {},
'Huilongguan': {}
},
'sun': {},
'Lower East Side': {}
},
'Shanghai': {
'Minhang ": {
" People's Square ": {
' Fried Chicken ': {}
}
},
' Zhabei ': {
' train station ': {
' Ctrip ' : {}
}
},
'Pudong': {}
},
'Shandong': {}
}
Because it is cyclic query, so write while
menu = curreen
Storage = []
the while True:
for K in curreen: # inside out menu data from the menu
print (k) # outermost layer of the printed data allows the user to select
choose = input ( '>>>:' ) .strip () # user accepts the output data is assigned to a variable the Choose
IF the Choose == 'q': # user to enter q to exit the program
exit ()
IF not the Choose: # determine the Continue if not properly output to the user out of the current line nothing do
if choose in curreen: # there is no determination in the menu of the user input
storage.append (choose) # enter each level of records stored in the list which
Print (Storage)
curreen = curreen [the Choose] # the next level mENU [ ] []
elif the Choose == 'b':
IF len (Storage) = 0:! # record list inside is not empty
curreen = storage.pop () # eject the last record and delete
the else:
Print ( 'already the top-most ')