一:制作要求

  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. Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals)

    A 题意:给你人的坐标,钥匙的坐标,办公室的坐标.要求所有人能够拿到钥匙并且走到办公室的最短时间.一个位置只能有一个人,一个位置只有一把钥匙,人和钥匙可以在同一个位置. 思路:DP+贪心,dp[i]表 ...

  2. MFC单文档视图程序简介

    在视图应用程序中,应用程序的数据由文档对象代表,数据的视图由视图对象代表.MFC的Cdocument类是文档对象的基类,Cview类是视图对象的基类.应用程序的主窗口,其操作功能在MFC的Cframe ...

  3. Centos6.5 安装MYSQL 5.5 -5.6.-5.7 一键yum快速安装 ,初始配置

    Centos6.5 安装MYSQL 5.5 ---5.6---5.7 一键yum快速安装 ,初始配置 第一步:安装mysql-5.5---- 5.6 ---- 5.7的yum源 [root@sv03 ...

  4. QEMU Networking

    QEMU Networking QEMU has a number of really nice ways to set up networking for its guests. It can be ...

  5. Apache Lucene全局搜索引擎入门教程

    Lucene简介 Lucent:Apache软件基金会Jakarta项目组的一个子项目,Lucene提供了一个简单却强大的应用程式接口,能够做全文索引和搜寻.在Java开发环境里Lucene是一个成熟 ...

  6. ubuntu 16.04 下安装动态链接库方法

    一般先使用ldd 来查看该应用程序缺少什么东西,然后,再根据sudo apt install XXX 去安装相应的动态库. 假如没有对应的库,可以使用: sudo ln -s /usr/lib/lib ...

  7. CSS box-sizing属性

    全文摘抄自 https://developer.mozilla.org/zh-CN/docs/Web/CSS/box-sizing 专门抄一遍是因为,我想当然的以为标准盒子模型设置的宽高是包括padd ...

  8. 【ABP框架系列学习】介绍篇(1)

      0.引言 该系列博文主要在[官方文档]及[tkbSimplest]ABP框架理论研究系列博文的基础上进行总结的,或许大家会质问,别人都已经翻译过了,这不是多此一举吗?原因如下: 1.[tkbSim ...

  9. (转)python异步编程--回调模型(selectors模块)

    原文:https://www.cnblogs.com/zzzlw/p/9384308.html#top 目录 0. 参考地址 1. 前言 2. 核心类 3. SelectSelector核心函数代码分 ...

  10. Pulsar Consumer实现介绍

    Pulsar-Consumer “Pulsar is a distributed pub-sub messaging platform with a very flexible messaging m ...