#---author:Administrator--- #---DATE:2019/4/15--- #---TIME:11:24--- menu = { '北京':{ '朝阳区':{ '国贸':{ '大裤衩':{}, 'CBD':{}, '购物':{}, }, '双井':{}, '劲松':{}, }, '海淀区':{}, '昌平区':{}, }, '上海':{}, '山西':{}, } current_layer = menu parent_layers = [] while True: for key in current_layer: print(key) chooice = input('>>>:').strip() if len(chooice) == 0:continue if chooice in current_layer: parent_layers.append(current_layer) current_layer = current_layer[chooice] elif chooice == 'b': if parent_layers: current_layer = parent_layers.pop() elif chooice == 'q': exit() else: print('非法输入,请重新输入:')