The following code is 3 level menu, which is based on the list. But there is still some errors I can't fix them: we can't go back main menu by pressing "b", even this command doesn't exist, I don't know if it is PyCharm's problem. I wii try to fix them later.ui
#多級字典及嵌套操做city_province = { "SiChuan" : { "ChengDu": { "JingJiangQu": ["銀石廣場", "春熙路"], "WuHouQu": ["武侯祠"] }, "MianYang":["345"], "DeYang":["678"], "LuZhou":["789"], "PanZhiHua":["91011"], "LeShan":["101112"], "GuangAn":["111213"] }, "GuiZhou": { "GuiYang": ["123"], "ZunYiShi": ["234"], "AnShunShi": ["345"], "FuQuanShi": ["456"], "KaiLiShi": ["567"], "XingYiShi": ["678"] }, "YunNan": { "KunMing": ["123"], "QuJing": ["234"], "YuXi": ["345"], "BaoShan": ["456"], "LiJiang": ["567"], "PuEr": ["678"], "XuanWei": ["789"] }}# print(city_province["YunNan"]["KunMing"][0])# print(city_province.values())# print(city_province.keys())while True: for index, i in enumerate(city_province): print(index, i) choice = input("input your province: ") if choice in city_province: while True: for i2 in city_province[choice]: print("\t", i2) choice_2 = input("input your city:") if choice_2 in city_province[choice]: while True: for i3 in city_province[choice][choice_2]: print("\t\t", i3) choice_3 = input("input your choice to get more details: ") if choice_3 in city_province[choice]: for i4 in city_province[choice][choice_2][choice_3]: print("\t\t", i4) choice_4 = input("press b to go back the main menu: ") if choice_4 == "b": pass if choice_3 == "b": break if choice_2 == "b": break