# 三级目录
info = {
# 一级
'ShanXi': {
# 二级
'JieXiu': {
# 三级
'XiaoSongQv': ['Burn here!'],
'SanSchool': ['Study here']
}
},
'BeiJing': {
'ChaoYang': {
'XianNinghou': ['Live here!']
},
'BeiYuan': {
'TieJian': ['Work Here!']
}
}
}
# 三级目录的跳转
# 定义标志
flag = False
while not flag:
for name1 in info:
print(name1)
# 选择1
choice = input('>>where?')
# 判断是否存在
if choice in info:
# 判断成功打印第二层
while not flag:
for name2 in info[choice]:
print(name2)
# 选择
choice2 = input('>>where?')
# 判断是否存在
if choice2 in info[choice]:
# 判断成功打印第三层
while not flag:
for name3 in info[choice][choice2]:
print(name3)
choice3 = input('>>where?')
if choice3 in info[choice][choice2]:
for name4 in info[choice][choice2][choice3]:
print(name4)
choice4 = input('最后一层,b返回,q退出!')
if choice4 == 'b':
pass # 占位符 我什么都不做
elif choice4 == 'q':
flag = True
elif choice3 == 'b':
break
elif choice3 == 'q':
flag = True
elif choice2 == 'b':
break
elif choice2 == 'q':
flag = True
# 输入B返回
elif choice == 'b':
pass
# 输入q退出
elif choice == 'q':
flag = True
或许你认为这个写法比较弱智,但是学习代码都是从麻烦到简单,学会了最原始的写法,能更好的了解运行机制,等后面学了函数等,就变得简单了。