隐藏页面特效

8-4 【Python0036】中文级联菜单

编写程序实现中文级联菜单,建议可以使用pypinyin或其它扩展库。

# 一、定义菜单内容 map_list ={ 'C盘':{ "program":{ "Microsoft Office":["IntegratedOffice.exe","OfficeClickToRun.exe"], "Microsoft SDKs":["locales","resources"] }, "Windows Media Player":{ "Media Renderer":["avtransport.xml","connectionmanager_dmr.xml"], "Network Sharing":["ConnectionManager.xml","ContentDirectory.xml"] }, "Windows NT": { "Accessories": ["en-US", "zh-CN"], "TableTextService": ["TableTextServiceArray.txt", "TableTextServiceDaYi.txt"] } }, 'D盘': { "课程": { "高数": ["高数一", "高数二"], "c++": ["第一章概轮", "第二章"] }, "活动": { "青马培训": ["线上笔记", "课后练习"], "软件杯": ["题目选择", "项目"] }, "作业":{ "高数": ["高数一", "高数二"], "操作系统": ["课后作业", "实验"] }, }, 'E盘': { "QQ": { "All Users": ["1161851172", "Registry2.0.db"], "MobileFile": ["Image", "mpFile"] }, "WeChat": { "Tencent": ["[3.6.0.18]", "appletPath.txt"], "WeChat Files": ["All Users", "Applet"] }, "Hadoop2.7.1": { "bin": ["container-executor", "hadoop"], "data": ["datanode", "namenode"] }, }, } while True: for menu_list in map_list: #定义一级联菜单,将已经完成级联的菜单传给新定义的数值menu_list print(menu_list) #打印一级菜单 # -------------------------------------------------------------------------------打印第一层输出,打印磁盘 chose_list = input("选择进入1>>:") #将用户输入定义为chose_list if chose_list in map_list: #判断用户输入,如果用户输入的数据在定义的字典里面,则为真 while True: for menu_list1 in map_list[chose_list]: #定义二级菜单menu_list1,如果用户输入的这个菜单在一级菜单里面,则进行打印 print("\t",menu_list1) # -------------------------------------------------------------------------------打印第二层输出,打印文件夹 chose_list1 = input("选择进入2>>:") #将用户输入定义为chose_list1 if chose_list1 in map_list[chose_list]: #判断用户输入,如果用户输入的数据在定义的字典里面,则为真 while True: for menu_list2 in map_list[chose_list][chose_list1]: #定义三级菜单menu_list2,如果用户输入的这个菜单在二级菜单里面,则进行打印 print("\t\t",menu_list2) # -------------------------------------------------------------------------------打印第三层输出,打印子文件夹 chose_list2 = input("选择进入3>>:") #将用户输入定义为chose_list2 if chose_list2 in map_list[chose_list][chose_list1]: #判断用户输入,如果用户输入的数据在定义的字典里面,则为真 for menu_list3 in map_list[chose_list][chose_list1][chose_list2]: #定义三级菜单menu_list3,如果用户输入的这个菜单在一级、二级、三级菜单里面,则进行打印 print("\t\t\t",menu_list3) # -------------------------------------------------------------------------------打印第三层区县里面所包含的具体文件夹或者文件 chose_list3 = input("最后一层,按b进行返回。>>:") #判断用户是否需要返回,返回上一层级 if chose_list3 == 'b': break # -------------------------------------------------------------------------------添加判断,来进行确认终端用户是否想要返回上级菜单。也就是返回上一级文件夹 if chose_list2 == 'b': #判断用户是否返回 break # -------------------------------------------------------------------------------添加判断,来进行确认终端用户是否想要返回上级菜单。也就是返回上一级文件夹 if chose_list1 == 'b': #判断用户是否返回 break

 


__EOF__

本文作者往心。
本文链接https://www.cnblogs.com/lx06/p/16211064.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   往心。  阅读(246)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
点击右上角即可分享
微信分享提示