• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
charlie、
博客园    首页    新随笔    联系   管理    订阅  订阅
三级菜单

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.

 

#多级字典及嵌套操作

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
posted on 2018-01-24 10:59  charlieCao  阅读(155)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3