三级菜单:

自己做的代码:

 china = {
'江苏':{
'南京':{
'江宁':{},
'白下':{},
'栖霞':{},
'江淮':{},
'浦口':{}
},
'宿迁':{
'宿城区':{},
'宿豫':{},
'泗阳':{},
'泗洪':{},
'沭阳':{}
},
'盐城':{
'盐都':{},
'亭湖':{},
'大丰':{},
}
},
'广州':{
'广东':{
'天河':{},
'白云':{},
'珠海':{}
},
'深圳':{
'罗湖':{},
'福田':{},
'南山':{}
},
'东莞':{
'莞城':{},
'长安':{},
'万江':{}
}
},
'浙江':{
'杭州':{
'下城':{},
'上城':{},
'西湖':{}
},
'宁波':{
'江东':{},'江北':{}
},
'温州':{
'龙湾':{},
'乐清':{},
'永嘉':{}
}
},
} flag_break = True while flag_break:
for key1 in china:
print(key1)
choice = input('please input your choice:>>>').strip()
if choice in china:
while flag_break:
for key2 in china[choice]:
print(key2)
choice2 = input('please input your choice:>>>').strip()
if choice2 in china[choice]:
while flag_break:
for key3 in china[choice][choice2]:
print(key3)
choice3 = input('please input your choice:>>>').strip()
if choice3 in china[choice][choice2]:
print('this is the last level')
elif choice3 == "q":
break
elif choice3 =='b':
flag_break = False
else:
print("无此项,请重新输入!")
elif choice2 == "q":
break
elif choice2 == 'b':
flag_break = False
else:
print("无此项,请重新输入!")
elif choice == "q":
break
elif choice == 'b':
flag_break = False
else:
print("无此项,请重新输入!")

老师讲的第一种方法:

 china = {
'江苏':{
'南京':{
'江宁':{},
'白下':{},
'栖霞':{},
'江淮':{},
'浦口':{}
},
'宿迁':{
'宿城区':{},
'宿豫':{},
'泗阳':{},
'泗洪':{},
'沭阳':{}
},
'盐城':{
'盐都':{},
'亭湖':{},
'大丰':{},
}
},
'广州':{
'广东':{
'天河':{},
'白云':{},
'珠海':{}
},
'深圳':{
'罗湖':{},
'福田':{},
'南山':{}
},
'东莞':{
'莞城':{},
'长安':{},
'万江':{}
}
},
'浙江':{
'杭州':{
'下城':{},
'上城':{},
'西湖':{}
},
'宁波':{
'江东':{},'江北':{}
},
'温州':{
'龙湾':{},
'乐清':{},
'永嘉':{}
}
},
} back_flag = False
exit_flag = False while not back_flag and not exit_flag:
for key in china:
print(key)
choice = input('1>>:').strip()
if choice == "q":
exit_flag = True
if choice in china:
while not back_flag and not exit_flag:
for key2 in china[choice]:
print(key2)
choice2 = input('2>>:').strip()
if choice2 == 'b':
back_flag = True
if choice2 == 'q':
exit_flag = True
if choice2 in china[choice]:
while not back_flag and not exit_flag:
for key3 in china[choice][choice2]:
print(key3)
choice3 = input('3>>:').strip()
if choice3 == 'b':
back_flag = True
if choice3 == 'q':
exit_flag = True
else:
back_flag = False
else:
back_flag = False
else:
back_flag = False

最新文章

  1. 那些年,坑死自己的事之fread/fwrite
  2. CVTE实习求职经历
  3. spring boot 框架 启动更新项目,以及生成 "实体_"文件
  4. CentOS 7系统挂载NTFS分区的移动硬盘(转载及体验 CentOS6.5系统挂载NTFS分区的移动硬盘)
  5. MNIST手写数字数据库
  6. VS2005上一个坑:关于pch 的 error C1023
  7. 对程序员的不尊重是中国it产业的悲哀。
  8. js Checkbox 传递多个值给后台
  9. Android SQLite 加密模块实现入门
  10. Makefile的伪目标
  11. MaxCompute在高德大数据上的应用
  12. 一、ESP8266入门(基于LUA开发)
  13. Python基础-python流程控制之循环结构(五)
  14. python note 07 集合
  15. Java代码安全
  16. js堆栈
  17. 【SPOJ10628】Count on a tree
  18. SURF 特征匹配
  19. 加密安装Kali Linux条件
  20. C++ STL 初探

热门文章

  1. JavaScript 延迟加载
  2. 讲讲网络模块中加解密那点儿事--AES+BASE64
  3. blfs(systemd版本)学习笔记-构建google-chrome浏览器
  4. 洛谷P4213 Sum(杜教筛)
  5. 中国最强AI超级服务器问世,每秒提供AI计算2000万亿次
  6. springboot 文件上传下载
  7. Spring学习之旅(四)Spring工作原理再探
  8. git 代码服务器的网页版gitweb的搭建
  9. git 入门教程之知识速查
  10. python如何实现类似php的引用赋值