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