# 编辑者:闫龙 #三级目录 menu = { ‘北京‘:{ ‘海淀‘:{ ‘五道口‘:{‘soho‘:{},‘网易‘:{},‘google‘:{}}, ‘中关村‘:{‘爱奇艺‘:{},‘汽车之家‘:{},‘youku‘:{},}, ‘上地‘:{‘百度‘:{},}, }, ‘昌平‘:{ ‘沙河‘:{‘老男孩‘:{},‘北航‘:{},}, ‘天通苑‘:{}, ‘回龙观‘:{}, }, ‘朝阳‘:{}, ‘东城‘:{}, }, ‘上海‘:{ ‘闵行‘:{ ‘人民广场‘:{‘炸鸡店‘:{}} }, ‘闸北‘:{ ‘火车战‘:{‘携程‘:{}} }, ‘浦东‘:{}, }, ‘山东‘:{}, } #定义一个用户输入列表,用来记录用户所输入的 UserSelect=[]; while True: if(len(UserSelect)==0): for i in menu.keys(): print(i); if(len(UserSelect)==1): if(UserSelect[-1] in menu): for i in menu[UserSelect[-1]].keys(): print(i); else: print("您输入的信息不在列表中"); UserSelect.pop(-1); continue; if (len(UserSelect) == 2): if (UserSelect[-1] in menu[UserSelect[-2]]): for i in menu[UserSelect[-2]][UserSelect[-1]].keys(): print(i); else: print("您输入的信息不在列表中"); UserSelect.pop(-1); continue; if (len(UserSelect) == 3): if (UserSelect[-1] in menu[UserSelect[-3]][UserSelect[-2]]): for i in menu[UserSelect[-3]][UserSelect[-2]][UserSelect[-1]].keys(): print(i); else: print("您输入的信息不在列表中"); UserSelect.pop(-1); continue; UserInput=input(">>>:").strip(); if(UserInput == "b"): if(len(UserSelect) == 0): print("已经是最高级了!"); continue; else: UserSelect.pop(-1); elif(UserInput == "q"): exit(); else: UserSelect.append(UserInput);
时间: 2024-12-14 13:07:30