循环用的多,之后再优化吧python
三级菜单:ide
data.txt 保存数据文件优化
{'河北':{ "石家庄":{"长安区":["oldboy","baidu","tencent"],"桥东区":["百事可乐","雪碧","芬达"]}, "邯郸":{ "丛台区":["新世纪","天鸿"]}}, '北京':{"西城区":{"宣武门":["锦江之星","汉庭","如家"],"广安门":["希尔顿","速8","7天"]}}}
menu.py 运行文件code
#!/use/bin/env python # -*- coding:utf-8 -*- f = open("data.txt","r",encoding="utf8") f=f.read() data=eval(f) # 把文本中内容转成字典 while True: for line in data: print(line) choice = input("选择进入1:") if choice in data: while True: for line2 in data[choice]: print("-->",line2) choice2 = input("选择进入2:") if choice2 in data[choice]: while True: for line3 in data[choice][choice2]: print("---->",line3) choice3 = input("选择进入3:") if choice3 in data[choice][choice2]: for line4 in data[choice][choice2][choice3]: print(line4) choice4 = input("最后一层,返回请按b,退出请按q:") if choice4 == "b": pass elif choice4 == "q": exit() elif choice3 == "b": break elif choice3 == "q": exit() elif choice2 == "b": break elif choice2 == "q": exit()