#python之三级目录低配版

menu = {
'北京':{
'朝阳':{
'国贸':{
'CICC':{ },
'HP':{ },
'渣打银行':{ },
'CCTV':{ },
},
'望京':{
'陌陌':{ },
'奔驰':{ },
'':{ },
},
'三里屯':{
'优衣库':{ },
'apple':{ },
},
},
'昌平':{
'沙河':{
'老男孩':{ },
'阿泰包子':{ },
},
'天通苑':{
'链家':{ },
'我爱我家':{ },
},
'回龙观':{ },
},
'海淀':{
'五道口':{
'谷歌':{ },
'网易':{ },
'搜狐':{ },
'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("1>>:").strip()
if choice=="q":
exit_flag=True
if choice in menu:
while not back_flag and not exit_flag:
for key2 in menu[choice]:
print(key2)
choice2=input("2>>:").strip()
if choice2 =='q':
exit_flag=True
if choice2 =='b':
back_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("3>>:").strip()
if choice3=='q':
exit_flag=True
if choice3=='b':
back_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("4>>:").strip()
print('last level')
if choice4=='q':
exit_flag=True
if choice4=='b':
back_flag=True
else:
back_flag=False
else:
back_flag=False
else:
back_flag=False
#python之三级目录高级版
menu = {
'北京':{
'朝阳':{
'国贸':{
'CICC':{ },
'HP':{ },
'渣打银行':{ },
'CCTV':{ }
},
'望京':{
'陌陌':{ },
'奔驰':{ },
'':{ }
},
'三里屯':{
'优衣库':{ },
'apple':{ }
}
},
'昌平':{
'沙河':{
'老男孩':{ },
'阿泰包子':{ }
},
'天通苑':{
'链家':{ },
'我爱我家':{ }
},
'回龙观':{ },
},
'海淀':{
'五道口':{
'谷歌':{ },
'网易':{ },
'搜狐':{ },
'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_layer=current_layer #改之前相当于护父亲
parent_layers.append(current_layer)
current_layer=current_layer[choice] #改成子层
elif choice == "b":
if parent_layers:
current_layer=parent_layers.pop()#弹出列表最后一个元素,并返回该元素的值
else:
print("无此项")

python之三级目录的更多相关文章

  1. python编辑三级目录

    一.需求分析 三级目录要能够实现以下要求: 显示根目录,任何子目录中都可以通过输入b字符来返回根目录 任何子目录中都可以通过输入q字符来返回上一级目录 主目录进入子目录后,系统能够打印子目录,根据指打 ...

  2. 用python选择及显示三级目录,可返回上层目录以及随时跳出。

    # -*- coding: utf-8 -*-"""Created on Fri Jul 29 09:43:38 2016 @author: yinggang" ...

  3. python学习笔记目录

    人生苦短,我学python学习笔记目录: week1 python入门week2 python基础week3 python进阶week4 python模块week5 python高阶week6 数据结 ...

  4. python打怪之路【第三篇】:利用Python实现三级菜单

    程序: 利用Python实现三级菜单 要求: 打印省.市.县三级菜单 可返回上一级 可随时退出程序 coding: menu = { '北京':{ '朝阳':{ '国贸':{ 'CICC':{}, ' ...

  5. python遍历一个目录,输出所有文件名

    python遍历一个目录,输出所有文件名 python os模块 os import os  def GetFileList(dir, fileList):  newDir = dir  if os. ...

  6. python之工作目录和文件引用

    1.参考 如何获得Python脚本所在目录的位置 Python 相对导入与绝对导入 还没细看 2.不考虑exe打包 sys.path[0] #顶层运行脚本的绝对目录 os.path.split(os. ...

  7. Python数据分析学习目录

    python数据分析学习目录 Anaconda的安装和更新 矩阵NumPy pandas数据表 matplotlib-2D绘图库学习目录                      

  8. 【转】python文件和目录操作方法大全(含实例)

    python文件和目录操作方法大全(含实例) 这篇文章主要介绍了python文件和目录的操作方法,简明总结了文件和目录操作中常用的模块.方法,并列举了一个综合实例,需要的朋友可以参考下一.python ...

  9. python获取指定目录下所有文件名os.walk和os.listdir

    python获取指定目录下所有文件名os.walk和os.listdir 觉得有用的话,欢迎一起讨论相互学习~Follow Me os.walk 返回指定路径下所有文件和子文件夹中所有文件列表 其中文 ...

随机推荐

  1. selenium自动化定位方式

    自动化定位方式 1.String Xpath = String.format("//*[@id=\"saveFileKeyWordsBtnHand\"]/../../.. ...

  2. ArcGIS发布地图服务时报错Error: ArcGIS Server site is currently being configured by another administrative operation. Please try again later.

    2017-06-06试图发布ArcGIS Server站点托管的服务时,返回以下错误消息: ERROR: Service 'test'.'MapServer' in folder '/' is cur ...

  3. Source Insight 4.0安装使用教程

    一.说明 Source Insight是什么:Source Insight是一款代码编缉.浏览.分析工具. Source Insight与文本编缉器有什么区别:Notepad++等文本编缉器也可以编缉 ...

  4. composer的安装方法 以及 ThinkPHP5安装

    1.下载installer的文件,使用浏览器开启链接:getcomposer.org/installer,下载如下文件到 E:\xs2016\composer, 将installer重命名为compo ...

  5. 使用JS判断不同的终端设备

    const ua: string = window.navigator.userAgent; const isWeixin: boolean = /MicroMessenger/i.test(ua); ...

  6. [CodeChef-CAPTCITI]Snakes capturing the Mongoose Cities

    Problem 每个点都可以选择降落士兵,然后当一个点的子节点被攻占的数量超过读入中的限制后,这个城市也被占领. 每个点降落士兵都有一定的代价,问把这一个图全部攻占的最小代价. Solution 这显 ...

  7. 整数中x出现的次数

    求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了.ACMer ...

  8. 【Alpha】测试报告

    测试中发现的Bug 测试伴随着前后端的首次连接之后与开发一起进行,在本阶段,我们遇到了各种各样的bug,有些体现在功能上,有些虽然不会影响到具体的功能实现,但是会影响到用户体验.由于时间问题,我们对其 ...

  9. CodeForces - 1101B

    题目: B. Accordion time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  10. 导航菜单点击图片切换--jquery

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...