# -*- coding: utf-8 -*-
# @Time : 2020/7/31 0:13
# @Author : Breeze
# @FileName: 三级菜单.py menu = {
'北京':{
'朝阳':{
'国贸':{
'CICC':{},
'HP':{},
'渣打银行':{}
},
'望京':{
'陌陌':{},
'奔驰':{},
'360':{},
},
'三里屯':{
'优衣库':{},
'apple':{},
},
},
'昌平':{
'沙河':{
'老男孩':{},
'阿泰包子':{}
},
'天通苑':{
'链家':{},
'我爱我家':{},
},
'回龙观':{},
},
'海淀':{
'五道口':{
'谷歌':{},
'网易':{},
'快手':{},
'SOHU':{},
'SOGO':{},
},
'中关村':{
'YOUKU':{},
'IQIYI':{},
'汽车之家':{},
'新东方':{},
'QQ':{},
},
},
},
'上海':{
'浦东':{
'陆家嘴':{
'CICC':{},
'高盛':{},
'摩根':{},
},
'外滩':{},
},
'闵行':{},
'静安':{}, },
'山东':{
'济南':{},
'德州':{
'乐陵':{
'丁务镇':{},
'城区':{},
},
'平原':{},
},
'青岛':{},
}
} back_flag = False
exit_flag = False
while not back_flag and not exit_flag:
for key in menu:
print(key)
choice = input('>>>:').strip()
if choice in menu:
while not back_flag and not exit_flag:
for key2 in menu[choice]:
print(key2)
choice2 = input('>>>:').strip()
if choice2 == 'b':
back_flag = True
if choice2 == 'q':
exit_flag = True
if choice2 in menu[choice]:
while not back_flag and not exit_flag:
for key3 in menu[choice][choice2]:
print(key3)
choice3 = input('>>>:').strip()
if choice3 == 'b':
back_flag = True
if choice3 == 'q':
exit_flag = True
if choice3 in menu[choice][choice2]:
while not back_flag and not exit_flag:
for key4 in menu[choice][choice2][choice3]:
print(key4)
choice4 = input('>>>:').strip()
print('last level')
if choice4 == 'b':
back_flag = True
if choice4 == 'q':
exit_flag = True
else:
back_flag = False
else:
back_flag = False
else:
back_flag = False
# -*- coding: utf-8 -*-
# @Time : 2020/7/31 1:29
# @Author : Breeze
# @FileName: 三级菜单high.py menu = {
'北京':{
'朝阳':{
'国贸':{
'CICC':{},
'HP':{},
'渣打银行':{}
},
'望京':{
'陌陌':{},
'奔驰':{},
'360':{},
},
'三里屯':{
'优衣库':{},
'apple':{},
},
},
'昌平':{
'沙河':{
'老男孩':{},
'阿泰包子':{}
},
'天通苑':{
'链家':{},
'我爱我家':{},
},
'回龙观':{},
},
'海淀':{
'五道口':{
'谷歌':{},
'网易':{},
'快手':{},
'SOHU':{},
'SOGO':{},
},
'中关村':{
'YOUKU':{},
'IQIYI':{},
'汽车之家':{},
'新东方':{},
'QQ':{},
},
},
},
'上海':{
'浦东':{
'陆家嘴':{
'CICC':{},
'高盛':{},
'摩根':{},
},
'外滩':{},
},
'闵行':{},
'静安':{}, },
'山东':{
'济南':{},
'德州':{
'乐陵':{
'丁务镇':{},
'城区':{},
},
'平原':{},
},
'青岛':{},
}
} current_layer = menu#实现动态循环
parent_layers = []#保存所有父级,最后一个元素永远是父级
while True:
for key in current_layer:
print(key)
choice = input('>>>:').strip()
if len(choice) == 0:
continue
if choice in current_layer:
parent_layers.append(current_layer)#在进入下一层之前,把当前层(也就是下一层父级)追加到列表中
#下一次loop,当用户选择b的时候,就可以直接去列表中最后一个值
current_layer = current_layer[choice]#改成了子层
elif choice == 'b' and parent_layers:
current_layer = parent_layers.pop()#取出列表中的最后一个值,因为他是当前层的父级
else:print('无此项')

三级菜单python编码及高级编码的更多相关文章

  1. 三级菜单python写法(递归写法)

    数据结构: menu = { '北京':{ '海淀':{ '五道口':{ 'soho':{}, '网易':{}, 'google':{} }, '中关村':{ '爱奇艺':{}, '汽车之家':{}, ...

  2. Py修行路 python基础 (五)三元运算 字符编码 元组 集合 三级菜单优化!

    三元运算 条件判断不能加冒号: a=3 b=5 c=a if a<b else b oct() 转成八进制的简写:16进制 标志:BH为后缀或是0x为前缀hex() 转成16进制 元组 跟列表是 ...

  3. 三级菜单的实现(python程序)

    这是刚开始写程序,三级菜单的程序基本是用字典实现,很low,以后学习了其他更好的东西,我会继续上传,然后争取在我水平高深之后,把这个简单的东西实现的狠高大上. _author_ = "zha ...

  4. 第一章:python基础语法| 字符编码| 条件语句...

    1.编程语言介绍 编程就是写代码,让计算机帮你做事情.计算机底层是电路,只认识二进制0和1.机器语言&汇编语言语言进化历史:机器.汇编.高级.机器语言只接受二进制代码:汇编语言是采用英文缩写的 ...

  5. Python基础2 字符编码和逻辑运算符

    编码 AscII码 :标准ASCII码是采用7位二进制码来编码的,最高为0,没有0000 0000,所以就是2**7-1=127个字符 , 当用1个字节(8位二进制码)来表示ASCII码时,就在最高位 ...

  6. 二、python数据类型、字符编码、文件处理

    一. 前言 1. 什么是数据: x = 10,10就是我们要存储的数据 2. 为何数据要分不同的类型 数据是用来表示状态的, 不同的状态就应该用不同类型的数据去表示 3. 数据类型 数字(整型.长整型 ...

  7. python学习笔记(字符串操作、字典操作、三级菜单实例)

    字符串操作 name = "alex" print(name.capitalize()) #首字母大写 name = "my name is alex" pri ...

  8. python语言中的编码问题(续)

    上文提到了python开发中非常重要的两处设置. 一个是编解码器的默认设置defaultencoding >>> import sys >>> sys.getdef ...

  9. python语言中的编码问题

    在编程的过程当中,常常会遇到莫名其妙的乱码问题.很多人选择出了问题直接在网上找答案,把别人的例子照搬过来,这是快速解决问题的一个好办法.然而,作为一个严谨求实的开发者,如果不从源头上彻底理解乱码产生的 ...

  10. 关于python中的字符串编码理解

    python2.x 中中间编码为unicode,一个字符串需要decode为unicode,再encode为其它编码格式(gbk.utf8等) 以gbk转utf8为例: s = "我是字符串 ...

随机推荐

  1. python学习:窗口程序

    https://www.cnblogs.com/zyg123/p/10385456.html # 导入tkinter模块 import tkinter # 创建画布需要的库 from matplotl ...

  2. VIM的撤销与恢复设置行数

    vim撤销操作:u vim恢复操作:ctrl+r 设置行数:    :set nu

  3. tcpdump: error while loading shared libraries: libpcap.so.1: cannot open shared object file: No such file or directory

    [root@inner ~]# tcpdump -i any -s 0 -w trunkm.pcaptcpdump: error while loading shared libraries: lib ...

  4. vue element 可编辑表格行内验证

    <template> <div class="page-layout rataMdel"> <el-button type="primary ...

  5. 原生js实现折线图

    不借助Echarts等图形框架原生JS快速实现折线图效果 1. 折线图效果预览 例如下图所示的折线图效果实现就很简单: 调用下面这段JS代码中的方法就好了: 假设页面上需要连接的所有点元素集合是ele ...

  6. jenkins 设置Git SSH凭证后,构建Git更新报错returned status code 128解决

    报错问题如下: Failed to connect to repository : Command "git ls-remote -h git@IP地址:python/django.git ...

  7. vue data functions should return an object

    报错: 原因:data里没写return{}

  8. zookeeper设置开机自启

    开机自启:(1)编辑zookeeper.service文件 vim /usr/lib/systemd/system/zookeeper.service 加入如下内容复制代码[Unit]Descript ...

  9. python调用lua脚本

    目录 lua代码 python代码 lua代码 入口函数是必须要填的 function test1(params) return 'test1:'..params end function test2 ...

  10. OSS管理文件(Node.js)

    let OSS = require('ali-oss'); let config = { region: 'oss-cn-hangzhou', //你的Region 注意 这个只要 空间名 不要 ht ...