python-编写程序实现中文级联菜单
编写程序实现中文级联菜单,建议可以使用pypinyin或其它扩展库。
代码:
address = { '河北': { '石家庄': { '石家庄铁道大学': { '信息学院': {}, '土木学院': {} }, '河北经贸大学': { '工商管理学院': {}, '计算机学院': {} }, }, '保定': { '华北电力大学': { '信息学院': {}, '土木学院': {} }, '河北大学': { '工商管理学院': {}, '计算机学院': {} } } } } get_info = False while not get_info: for i in address: print(i) choice = input('请输入城市1:') if choice in address: # 不是'='是判断是否在字典中 while not get_info: for i2 in address[choice]: print('\t', i2) break choice2 = input('请输入城市2:') if choice2 in address[choice]: while not get_info: for i3 in address[choice][choice2]: print('\t\t', i3) break choice3 = input('请输入城市3:') if choice3 in address[choice][choice2]: for i4 in address[choice][choice2][choice3]: print('\t\t\t', i4) break choice4 = input('最后一层,按p返回!') if choice4 == 'p': pass if choice4 == 'b': get_info = True if choice3 == 'p': break if choice3 == 'b': get_info = True if choice2 == 'p': break if choice2 == 'b': get_info = True
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!