一:制作要求

  1.三级菜单
  2.可依次选择进入各子菜单
  3.所需新知识点:字典,列表

  *本文通过三种方法完成,第一种:只使用循环,第二种:使用列表,第三种:使用字典

二:FlowChart流程图

  

与上图对应,实现方式图解:

while用来判断输入的数据和允许输入数据中的哪一项匹配,if来进行判断是否退出本次循环,

三:具体实现代码:

  1.没有使用列表字典 

  

 #三级菜单 输入都是用一个变量   0120使用字典,列表

 #思路:while
#定义一级菜单
msg='''
请输入你要进行的操作前面的索引(1,2,3,b): 1.北京
2.上海
3.香港
b.退出
'''
#定义二级菜单
msg_1='''
1.朝阳区
2.西城区
3.海淀区
b.返回上一级
'''
msg_2_2='''
1.西城区_A
2.西城区_B
3.西城区_C
b.返回上一级
'''
#定义三级菜单
msg_2_1='''
1.朝阳区_A
2.朝阳区_B
3.朝阳区_C
b.返回上一级
'''
while True:
#输出一级菜单:
print(msg)
select_input=input("请输入你的选择:")
#选项一
while select_input== "":
print(msg_1)
select_input_1 = input("请输入你的选择:")
while select_input_1 == "":
print(msg_2_1)
select_input_2 = input("请输入你的选择:")
if select_input_2=="b":
break
while select_input_1 == "":
print(msg_2_2)
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
while select_input_1 == "":
print(msg_2_2)
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
if select_input_1== "b":
break
#选项二
while select_input == "":
print(msg_1)
select_input_1 = input("请输入你的选择:")
while select_input_1 == "":
print(msg_2_1)
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
while select_input_1 == "":
print(msg_2_2)
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
while select_input_1 == "":
print(msg_2_2)
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
if select_input_1 == "b":
break
#选项三
while select_input == "":
print(msg_1)
select_input_1 = input("请输入你的选择:")
while select_input_1 == 1:
print(msg_2_1)
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
while select_input_1 == "":
print(msg_2_2)
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
while select_input_1 == "":
print(msg_2_2)
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
if select_input_1 == "b":
break
#选项四
if select_input=="b":
break
print("本次使用结束!")

  

  2.使用列表 

  

 # 三级菜单 输入都是用一个变量   0120使用字典,列表

 # 思路:while
# 通过定义列表进行选项存储
list=["北京","上海","香港","退出"]
list_1=["朝阳区","西城区","海淀区","返回上一级"]
list_1_1=["朝阳区_A","朝阳区_B","朝阳区_C","返回上一级"]
list_1_2=["西城区_A","西城区_B","西城区_C","返回上一级"]
while True:
# 输出一级菜单:
for i in list:
print(" \n%s: %s"%(list.index(i)+1,i))
select_input = input("请输入你的选择:")
# 选项一
while select_input == "":
for i in list_1:
print(" \n%s: %s" % (list_1.index(i) + 1, i))
select_input_1 = input("请输入你的选择:")
while select_input_1 == "":
for i in list_1_1:
print(" \n%s: %s" % (list_1_1.index(i) + 1, i))
select_input_2 = input("请输入你的选择:")
if select_input_2 == "":
break
while select_input_1 == "":
for i in list_1_2:
print(" \n%s: %s" % (list_1_2.index(i) + 1, i))
select_input_2 = input("请输入你的选择:")
if select_input_2 == "":
break
while select_input_1 == "":
for i in list_1_2:
print(" \n%s: %s" % (list_1_2.index(i) + 1, i))
select_input_2 = input("请输入你的选择:")
if select_input_2 == "":
break
if select_input_1 == "":
break
# 选项二
while select_input == "":
for i in list_1:
print(" \n%s: %s" % (list_1.index(i) + 1, i))
select_input_1 = input("请输入你的选择:")
while select_input_1 == "":
for i in list_1_2:
print(" \n%s: %s" % (list_1_2.index(i) + 1, i))
select_input_2 = input("请输入你的选择:")
if select_input_2 == "":
break
while select_input_1 == "":
for i in list_1_2:
print(" \n%s: %s" % (list_1_2.index(i) + 1, i))
select_input_2 = input("请输入你的选择:")
if select_input_2 == "":
break
while select_input_1 == "":
for i in list_1_2:
print(" \n%s: %s" % (list_1_2.index(i) + 1, i))
select_input_2 = input("请输入你的选择:")
if select_input_2 == "":
break
if select_input_1 == "":
break
# 选项三
while select_input == "":
for i in list_1:
print(" \n%s: %s" % (list_1.index(i) + 1, i))
select_input_1 = input("请输入你的选择:")
while select_input_1 == 1:
for i in list_1_2:
print(" \n%s: %s" % (list_1_2.index(i) + 1, i))
select_input_2 = input("请输入你的选择:")
if select_input_2 == "":
break
while select_input_1 == "":
for i in list_1_2:
print(" \n%s: %s" % (list_1_2.index(i) + 1, i))
select_input_2 = input("请输入你的选择:")
if select_input_2 == "":
break
while select_input_1 == "":
for i in list_1_2:
print(" \n%s: %s" % (list_1_2.index(i) + 1, i))
select_input_2 = input("请输入你的选择:")
if select_input_2 == "":
break
if select_input_1 == "":
break
# 选项四
if select_input == "":
break
print("本次使用结束!")
使用列表运行效果和第一种方法类似,只不过把返回的值改成了4,

  3.使用字典

  

# 三级菜单 输入都是用一个变量   0120使用字典,列表

# 思路:while
# 通过字典进行选项存储
dic={
"1.北京":{
"1.朝阳区":["朝阳区_A","朝阳区_B","朝阳区_C","返回上一级"],
"2.西城区":["西城区_A","西城区_B","西城区_C","返回上一级"],
"3.海淀区":[],
"4.返回上一级":[]
},
"2.上海":{},
"3.香港":{},
"b.退出":{}
} while True:
# 输出一级菜单:
print(dic.keys())
select_input = input("请输入你的选择:")
# 选项一
while select_input == "":
print(dic["1.北京"].keys())
select_input_1 = input("请输入你的选择:")
while select_input_1 == "":
print(dic["1.北京"]["1.朝阳区"])
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
while select_input_1 == "":
print(dic["1.北京"]["1.朝阳区"])
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
while select_input_1 == "":
print(dic["1.北京"]["1.朝阳区"])
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
if select_input_1 == "b":
break
# 选项二
while select_input == "":
print(dic["1.北京"].keys)
select_input_1 = input("请输入你的选择:")
while select_input_1 == "":
print(dic["1.北京"]["1.朝阳区"])
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
while select_input_1 == "":
print(dic["1.北京"]["1.朝阳区"])
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
while select_input_1 == "":
print(dic["1.北京"]["1.朝阳区"])
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
if select_input_1 == "b":
break
# 选项三
while select_input == "":
print(dic["1.北京"].keys)
select_input_1 = input("请输入你的选择:")
while select_input_1 == 1:
print(dic["1.北京"]["1.朝阳区"])
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
while select_input_1 == "":
print(dic["1.北京"]["1.朝阳区"])
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
while select_input_1 == "":
print(dic["1.北京"]["1.朝阳区"])
select_input_2 = input("请输入你的选择:")
if select_input_2 == "b":
break
if select_input_1 == "b":
break
# 选项四
if select_input == "b":
break
print("本次使用结束!")

四:运行效果截图(第一种方法):


五:注意事项

  1.Python虽然简单,但是一定要熟练掌握格式,有的时候差一个空格都会出错而且还不容易排除错误.
  2.关于语句:
    select_input=b
    while int(select_input)==1
    运行报错:ValueError: invalid literal for int() with base 10: 'b',
    语法错误
    出错原因:Python3.0以后的版本不能进行字符串转换类型之后与数字之间的比较与判断
    所以改成:select_input=="1"

Python_简单三级菜单制作的更多相关文章

  1. HTML+CSS实现简单三级菜单

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. python三级菜单制作 day4

    需求:可依次选择进入各子菜单可从任意一层往回退到上一层可从任意一层退出程序所需新知识点:列表.字典 数据结构: menu = {    '北京':{        '海淀':{            ...

  3. python_入门_三级菜单

    '''程序:三级菜单要求:1.打印省.市.县三级菜单2.可返回上一级3.可随时退出程序''' # -*- coding: utf-8 -*- # __author__ = 'qi' prov_city ...

  4. Python学习-------------------三级菜单简单版

    题目: 多级菜单         1.三级菜单         2.可依次选择进入的各子菜单         3.所需新知识点:列表.字典 ReadMe: 这个做循环,比较绕脑子 点开运行即可 Min ...

  5. Python3学习之路~2.5 简单的三级菜单程序

    程序:三级菜单 需求: 1.打印省.市.县三级菜单2.可返回上一级3.可随时退出程序 代码1: data={ "山东":{ "济南":["历下区&qu ...

  6. vue的递归组件以及三级菜单的制作

    js里面有递归算法,同时,我们也可以利用props来实现vue模板的递归调用,但是前提是组件拥有 name 属性 父组件:slotDemo.vue: <template> <div& ...

  7. python(5)- 简单练习:python三级菜单优化

    python三级菜单优化,菜鸟版链接:http://www.cnblogs.com/xuyaping/p/6648170.html menu = { '北京':{ '海淀':{ '五道口':{ 'so ...

  8. 纯css制作三级菜单

    <!DOCTYPE html> <html> <head> <title>三级菜单</title> <meta charset=&qu ...

  9. css三级菜单效果

    一个简单实用的css三级菜单效果 <!doctype html> <html> <head> <meta charset="utf-8"& ...

随机推荐

  1. 如何高效地写CSS--等以后有空多加总结一下

    CSS写的并不多,如果从零开始的项目,自己一定想搬砖来得容易点.CSS编写一定有其工程化的方法,来时编写更加有效率. 考虑将CSS的预处理LESS.Sass或Stylus引入,或者将CSS的后处理Po ...

  2. Chapter 1: Plug-in programing from past to the future

    It is the best time. Although the internal API of Android not allowed to be modified by google play, ...

  3. 【CF429E】 Points and Segments(欧拉回路)

    传送门 CodeForces 洛谷 Solution 考虑欧拉回路有一个性质. 如果把点抽出来搞成一条直线,路径看成区间覆盖,那么一个点从左往右被覆盖的次数等于从右往左被覆盖的次数. 发现这个性质和本 ...

  4. JAVA泛型实现原理

    1. Java范型时编译时技术,在运行时不包含范型信息,仅仅Class的实例中包含了类型参数的定义信息.泛型是通过java编译器的称为擦除(erasure)的前端处理来实现的.你可以(基本上就是)把它 ...

  5. Java核心技术卷一基础知识-第14章-多线程-读书笔记

    第 14 章 多线程 本章内容: * 什么是线程 * 中断线程 * 线程状态 * 线程属性 * 同步 * 阻塞队列 * 线程安全的集合 * Collable与Future * 执行器 * 同步器 * ...

  6. Core 读取配置文件

    新建控制台 static void Main(string[] args) { Console.WriteLine("Hello World!"); //获取应用程序的当前工作目录 ...

  7. flash中调用XML遇到的中文显示异常问题

    昨天使用flash调用XML文件进行显示时,出现了中文无法显示的问题,记录一下解决方法: 1.字体设置: 一般flash里的动态文本和嵌入文本都是默认的使用Arial字体,这个字体里可能没有中文,所以 ...

  8. ImportError: No module named '_tkinter', please install the python3-tk package

    ImportError: No module named '_tkinter', please install the python3-tk package 先更新包,命令:sudo apt-get ...

  9. Quartz的使用案例

    一.介绍 项目中的调度任务可以使用Quartz任务调度框架 1.Job接口:这个接口里面只定义了一个方法,excute void execute(JobExecutionContext context ...

  10. Java的运行原理(转载)

    在Java中引入了虚拟机的概念,即在机器和编译程序之间加入了一层抽象的虚拟的机器.这台虚拟的机器在任何平台上都提供给编译程序一个的共同的接口.编译程序只需要面向虚拟机,生成虚拟机能够理解的代码,然后由 ...