博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Day1:Python编写三级菜单
阅读量:6469 次
发布时间:2019-06-23

本文共 3516 字,大约阅读时间需要 11 分钟。

听取了Alex老师的话,程序里面尽量用英文,本人编程小白,英语菜鸟,英语不会的地方有用中文表示了,显得代码有些乱,不足之处请多多指教!

catalog = {           #在此定义一个三级菜单     "food":{ "fruit":["apple","pear","litchi","banana","watermelon"],              "vegetable":["potato","pumpkin","leek","spinach","cowpea"],              "dessert":["cake","cookie","chocolate","butter","ice cream"]},     "furniture":{"electric":["television","washing machine","freezer","microwave oven"],                  "wood":["door","table","bed","cabinet","safa"],                  "vehicle":["bicycle","motorcycle","car"]},     "year":{"season":["spring","summer","autumn","winter"],             "month":["January","February","March","April","May","June","July","August","September","October","November","December"],             "festival":["spring festival","april fool's day","Labour Day","valentine's say","Christmas"] } } print("+-------------------------+")  #打印菜单选项栏 print("+---see  the catalog: C---+") print("+---quit the catalog: Q---+") print("+---Back         up : B---+") print("+-------------------------+") temp = True                           #定义一个用于可随时终止循环的变量 def firt_catalog(first_level):        #定义一级目录菜单选项格式
   if first_level.lower() == "q":    #系统在打印了根目录时,用户输入Q,则直接返回False,将false传递while循环的temp中,终止循环退出程序     return False
elif first_level.lower() == "b":  #用户输入B之后,返回上一层菜单,因为最初为根目录。打印提示根目录         print("已经是根目录了!")         return False     else:                               #如果用户输入的是一级菜单的选项,则打印对应的二级菜单         for each2 in catalog[first_level]:             print(each2 + ",", end="")         print("\nselect level 2 catalog or other choose:")         second_level = input("pleace choose:")  #用户做出选择         second_catalog(first_level,second_level)  #跳转到二级菜单选择函数中,并将用户选择结果传递到二级菜单选项函数 def second_catalog(first,second):                 #定义二级菜单选项函数     if second.lower() == "q":         return False     elif second.lower() == "b":                  #如果用户输入B,则返回上级目录         for each in catalog:                     #打印上级目录             print(each + ",", end="")         print("\nselect level 1 catalog or other choose:")         first_level = input("pleace choose:")            firt_catalog(first_level)                #打印完上级目录之后,因为用户又返回到了一级目录,所以此处又去调用一级目录菜单选择函数     else:                                        #如果用户输入二级目录菜单的元素,则打印该元素下的三级目录菜单         for each3 in catalog[first][second]:                  print(each3 + ",", end="")         print("\nselect level 3 catalog or other choose:")         third_choose = input("pleace choose:")         third_catalog(first,second,third_choose)        #进入三级目录菜单选择函数 def third_catalog(first,second,third):                   #定义一个三级目录菜单     if third.lower() == "q":         return False     elif third.lower() == "b":         for each2 in catalog[first]:             print(each2 + ",", end="")         print("\nselect level 2 catalog or other choose:")         second_level = input("pleace choose:")         second_catalog(first,second_level)     else:         return False user_choose = input("pleace choose:")     #用户根据系统提示的选项卡做出选择 while temp:                               #此处用一个变量作为循环的判断条件,当用户退出后,或者选择了第三级目录菜单则直接修改变量值,用于终止循环     if user_choose.lower() == "c":         for each in catalog:             print(each + ",", end="")         print("\nselect level 1 catalog or other choose:")         first_level = input("pleace choose:")         temp = firt_catalog(first_level)      elif user_choose.lower() == "b":         print("已经是根目录了!")         temp = False     else:         temp = False

转载于:https://www.cnblogs.com/louisyang/p/9556655.html

你可能感兴趣的文章
正则表达式分解剖析(一文悟透正则表达式)
查看>>
解决UILable标点符号居中的问题
查看>>
HTML5新特性教程
查看>>
SpringBoot 实战 (十七) | 整合 WebSocket 实现聊天室
查看>>
ImageOptim-无损图片压缩Mac版
查看>>
12 Go语言map底层浅析
查看>>
vue-resumer 项目中 element-ui 遇到的 textarea autosize 问题
查看>>
以主干开发作为持续交付的基础
查看>>
Tech UP——EGO北京分会成立啦
查看>>
PHP扩展库PEAR被攻击,近半年下载者或被影响
查看>>
传统运维团队转型应该注意哪些问题?
查看>>
JavaScript函数(二)
查看>>
Airbnb改进部署管道安全性,规范部署顺序
查看>>
腾讯最大规模裁撤中层干部,让贤年轻人
查看>>
当我们谈性能的时候,我们实际上在谈什么?
查看>>
Spring Boot 2.0将会增强Actuator端点的特性
查看>>
i4o开源项目增强LINQ索引功能
查看>>
蔡超:入门 Go 语言必须跨越的五个思维误区
查看>>
使用Akka Actor和Java 8构建反应式应用
查看>>
curl常用命令详解
查看>>