码迷,mamicode.com
首页 > 其他好文 > 详细

三级菜单 问题及改进

时间:2018-04-12 13:44:50      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:--   continue   this   退出   while   print   pop   lis   pen   

#
# 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!‘)

三级菜单 问题及改进

标签:--   continue   this   退出   while   print   pop   lis   pen   

原文地址:https://www.cnblogs.com/nfyx/p/8806833.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!