libra-gyf

三级列表

menu = {
    '1.魏国':{
        '1.主公':{'1.曹操':['孟德'],'2.曹丕':['子桓'],'3.曹睿':['元仲']},
        '2.谋士':{'1.司马懿':['仲达'],'2.郭嘉':['奉孝'],'3.贾诩':['文和']},
        '3.武将':{'1.许褚':['仲康'],'2.张辽':['文远'],'3.徐晃':['公明']}
    },
    '2.蜀国':{
        '1.主公':{'1.刘备':['玄德 '],'2.刘禅:':['公嗣'],},
        '2.谋士':{'1.诸葛亮':['孔明'],'2.庞统':['士元'],'3.徐庶':['元直']},
        '3.武将':{'1.关羽':['云长'],'2.张飞':['翼德'],'3.赵云':['子龙']}
    },
    '3.吴国': {
    '1.主公':{'1.孙权': ['仲谋 '], '2.孙策:':['伯符'], '3.孙坚:':['文台']},
    '2.谋士': {'1.陆逊': ['伯言'], '2.周瑜:':['公瑾'], '3.鲁肃':['子敬']},
    '3.武将': {'1.吕蒙': ['子明'], '2.甘宁:':['兴霸'], '3.太史慈':['子义']}
    }
}
current_layer = menu  #实现动态循环
#parrent_layer = menu
parrent_layer = []   #保存父亲级,最后一个元素永远都是父亲级别
while True:
    for key in current_layer:
        print(key)
    choice = input(">>>").strip()
    if len(choice) == 0:
        continue
    if choice in current_layer:
        parrent_layer.append(current_layer)
        current_layer = current_layer[choice]
    elif choice == 'b':
        if parrent_layer:
            current_layer = parrent_layer.pop()
    else:
        print('无此项')

  

posted on 2019-12-12 14:26  libra-gyf  阅读(140)  评论(0编辑  收藏  举报

导航