menu = { "深圳":{ "罗湖":{ "罗湖火车站": {}, "东门": {}, "国贸": {}, "布心": {}, }, "福田":{ "香蜜湖": {}, "华强北": {}, "华强南": {}, "市民中心": {}, }, "南山": { "南山中心城": {}, "南头关": {}, "华侨城": {}, }, "宝安": { "宝安中心": {}, "西乡": {}, "松岗": {}, }, "龙岗": { "龙岗中心城": {}, "布吉": {}, "坂田": {}, }, }, "湖南":{ "长沙": { "大学城区":{}, }, "衡阳":{ "衡阳":{ "火车站":{}, }, }, "郴州":{ "北湖区": {}, "苏仙区": {}, "东湖区": {}, }, }, "北京":{}, } current_layer = menu parent_layer = [] while True: for key in current_layer: print(key) choice = input(">>>>:").strip() if len(choice) == 0:continue if choice in current_layer: parent_layer.append(current_layer) current_layer = current_layer[choice] elif choice == "b": current_layer = parent_layer.pop() else: print("NO")