把三级菜单输出,选择后逐层显示,”b“返回上一级菜单。
 menu = {
'北京':{
'海淀':{
'五道口':{
'soho':{},
'网易':{},
'google':{}
},
'中关村':{
'爱奇艺':{},
'汽车之家':{},
'youku':{},
},
'上地':{
'百度':{},
},
},
'昌平':{
'沙河':{
'老男孩':{},
'北航':{},
},
'天通苑':{},
'回龙观':{},
},
'朝阳':{},
'东城':{},
},
'上海':{
'闵行':{
"人民广场":{
'炸鸡店':{}
}
},
'闸北':{
'火车战':{
'携程':{}
}
},
'浦东':{},
},
'山东':{},
}
二逼青年版:
 while True:
for key in menu:
print(key)
choice = input(">>>:")
if len(choice) == 0: continue
if choice not in menu:continue
while True:
for key2 in menu[choice]:
print(key2)
choice2 = input(">>>:")
if len(choice2) == 0: continue
if choice2 == "b": break
if choice2 not in menu[choice]: continue
while True:
for key3 in menu[choice][choice2]:
print(key3)
choice3 = input(">>>:")
if len(choice3) == 0: continue
if choice3 == "b": break
if choice3 not in menu[choice][choice2]: continue
while True:
for key4 in menu[choice][choice2][choice3]:
print(key4)
choice4 = input(">>>:")
if len(choice4) == 0: continue
if choice4 == "b": break
if choice4 not in menu[choice][choice2][choice3]: continue

文艺青年版:

 current_level = menu
last_level = []
while True:
for key in current_level:
print(key)
choice = input(">>>:")
if len(choice) == 0:continue
if choice == "b":
if not last_level : break
current_level = last_level[-1]
last_level.pop()
if choice not in current_level:continue
last_level.append(current_level)
current_level = current_level[choice]

[terry笔记]python三级菜单的更多相关文章

  1. python三级菜单实例(傻瓜版和进阶版)

    程序: python三级菜单 要求: : 1.打印省.市.县三级菜单 2.可返回上一级 3.可随时退出程序 方案一:傻瓜版(其实傻瓜版考察的主要是思路!思路清楚了,那才不是傻瓜!O(∩_∩)O哈哈~) ...

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

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

  3. python三级菜单的实现

    一.作业要求 1.使用字典实现三级菜单功能 2.直接输入前面数字进入下一级菜单 3.按B返回上一级,按Q退出 二.需要知识点 1.if循环 2.for循环,enumerate的用法 3.while循环 ...

  4. python 三级菜单 while循环三次,湖北省市-县-街道的选择,3个while的循环 -day2

    python编写一个三级while的循环菜单 1.定义字典,字典里面嵌套字典,内嵌字典的值为列表. 思路: 湖北省的市:字典中的定义3个字典,用于存储{序列-键:市名} shiqu_dir = {} ...

  5. Python 三级菜单 增强版

    需要实现的功能是:三级菜单1.从文本内读出选项2.查询每一级的选项,并能对选项进行增/删/改功能3.每一级可以退出程序或者返回上一层 2018-5-14 更新内容 思路 实现过程中的BUG及解决方案: ...

  6. python三级菜单

    #-*- coding:utf-8 -*-#Author:gxli #一级菜单项def menu(): #遍历字典dic一级菜单 print('-----------一级菜单------------- ...

  7. Python 三级菜单与优化(一层循环嵌套)

    优化的思路是使用单层循环嵌套完成三级菜单,这个优化思路我非常喜欢,我喜欢在编程的时候用最少的东西写出同样的效果,通常这样会绕来绕去,但非常有趣!!! 需求: 1.运行程序输出第一级菜单: 2.选择一级 ...

  8. Python——三级菜单

    #三级菜单函数 menu = { '北京':{ 海淀:{ '五道口':{} '中关村':{} '上帝':{} } '昌平':{} '朝阳':{} '东城':{} }, '上海':{} '山东':{} ...

  9. 4th,Python三级菜单

    1. 运行程序输出第一级菜单 2. 选择一级菜单某项,输出二级菜单,同理输出三级菜单 3. 菜单数据保存在文件中 4. 让用户选择是否要退出 5. 有返回上一级菜单的功能 data = { '北京': ...

随机推荐

  1. Emgu cv人脸检测识别

    Emgu cv人脸检测识别 1.开发平台:WIN10 X64    VS2012    Emgucv版本:3.1 2.先给大家分享一个官网给的示例源代码: https://ncu.dl.sourcef ...

  2. 警告: The APR based Apache Tomcat Native library failed to load.

    警告: The APR based Apache Tomcat Native library failed to load. The error reported was [C:\apache-tom ...

  3. 计算机网络系统--常用DOS命令

    01.名称:md 用法:md “文件夹名” 用处:批量建立文件夹 02.关机命令 shutdown At 18:00 shutdown –s      18:00关机 shutdown -s -t 3 ...

  4. thrift 版本不一致导致 @Override 报错

    thrift 版本不一致导致 @Override 报错 学习了:http://blog.csdn.net/antony1776/article/details/78920888 版本不一致导致的: 在 ...

  5. Spring使用HibernateDaoSupport操作数据

    spring提供了一个数据訪问层的类:org.springframework.orm.hibernate3.support.HibernateDaoSupport.一般是让 dao继承该类,然后在da ...

  6. spring batch(一):基础部分

    spring batch(一):基础部分 博客分类: Spring java   spring batch 官网: http://www.springsource.org/spring-batch 下 ...

  7. Qt 图像处理之 灰度变换

    对图像的亮度.对照度进行变换是非经常常使用的一种图像处理操作,可是Qt 本身却没有提供对应的功能代码.因此我写了个简单的类来实现这些操作.我把这个类称为 BrightnessMapper. 代码例如以 ...

  8. 英语发音规则---D字母

    英语发音规则---D字母 一.总结 一句话总结: 1.D发[d]音? doctor ['dɒktə] n. 医生:博士 bread [bred] n. 面包:生计 hand [hænd] n. 手,手 ...

  9. PHP substr() 函数截取中文字符串乱码

    用PHP substr() 函数截取中文字符串乱码,换PHPmb_substr() 函数即可

  10. Vmware 安装samba之二

    安装samba:sudo apt-get install samba 安装smbclient:sudo apt-get install 安装smbfs:sudo apt-get smbfs 2.修改配 ...