三级菜单 问题及改进
Posted 牛粪也香
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了三级菜单 问题及改进相关的知识,希望对你有一定的参考价值。
#
# lla={
# ‘sheng‘:{
# ‘shi‘:{
# ‘xian‘:{
# ‘qu‘:{},
# ‘qu‘:{},
# ‘qu‘:{},
# ‘qu‘:{},
# },
# ‘xian‘:{‘qu‘:{},},
# ‘xian‘:{‘qu‘:{},},
# },
# ‘shi‘:{‘xian‘:{‘qu‘:{},},},
# ‘shi‘:{‘xian‘:{‘qu‘:{},},},
# },
# ‘sheng‘:{‘shi‘:{‘xian‘:{‘qu‘:{},},},},
# }
#
#
ll={
‘sheng‘:{
‘shi1‘:{
‘xian1‘:{
‘qu1‘:{},
‘qu2‘:{},
‘qu3‘:{},
},
‘xian2‘:{
‘qu21‘:{},
‘qu21‘:{},
‘qu23‘:{},
},
},
‘shi2‘:{
‘xian21‘:{
‘qu211‘:{},
‘qu212‘:{},
‘qu213‘:{},
},
‘xian22‘:{
‘qu221‘:{},
‘qu222‘:{},
‘qu223‘:{},
},
},
},
‘sheng2‘: {
‘shi1‘: {
‘xian1‘: {
‘qu1‘: {},
‘qu2‘: {},
‘qu3‘: {},
},
‘xian2‘: {
‘qu21‘: {},
‘qu21‘: {},
‘qu23‘: {},
},
},
‘shi2‘: {
‘xian21‘: {
‘qu211‘: {},
‘qu212‘: {},
‘qu213‘: {},
},
‘xian22‘: {
‘qu221‘: {},
‘qu222‘: {},
‘qu223‘: 333,
},
},
},
}
while True:
for sheng in ll:
print(sheng)
sheng = input("choice sheng :").strip()
if sheng in ll:
print(sheng)
while True:
for shi in ll[sheng]:
print(shi)
shi = input("choice shi :").strip()
if shi in ll[sheng]:
while True:
for xian in ll[sheng][shi]:
print(xian)
xian = input(‘choice xian:‘).strip()
if xian in ll[sheng][shi]:
while True:
for xian in ll[sheng][shi][xian]:
print(xian)
print(‘this is the last one‘)
2--------------------改进-----------------------------------------
ll={
‘sheng‘:{
‘shi1‘:{
‘xian1‘:{
‘qu1‘:{},
‘qu2‘:{},
‘qu3‘:{},
},
‘xian2‘:{
‘qu21‘:{},
‘qu21‘:{},
‘qu23‘:{},
},
},
‘shi2‘:{
‘xian21‘:{
‘qu211‘:{},
‘qu212‘:{},
‘qu213‘:{},
},
‘xian22‘:{
‘qu221‘:{},
‘qu222‘:{},
‘qu223‘:{},
},
},
},
‘sheng2‘: {
‘shi1‘: {
‘xian1‘: {
‘qu1‘: {},
‘qu2‘: {},
‘qu3‘: {},
},
‘xian2‘: {
‘qu21‘: {},
‘qu21‘: {},
‘qu23‘: {},
},
},
‘shi2‘: {
‘xian21‘: {
‘qu211‘: {},
‘qu212‘: {},
‘qu213‘: {},
},
‘xian22‘: {
‘qu221‘: {},
‘qu222‘: {},
‘qu223‘: 333,
},
},
},
}
layer = ll
parent_list = []
while True:
for key in layer:
print(key)
xia = input("input a name:").strip()
if len(xia) == 0: continue
if xia in layer:
parent_list.append(layer)
layer = layer[key]
elif xia == ‘b‘:
if parent_list:
layer = parent_list.pop()
elif xia == ‘q‘:
exit(‘退出程序!‘)
else:
print(‘please input a right str!‘)
以上是关于三级菜单 问题及改进的主要内容,如果未能解决你的问题,请参考以下文章