Python 21 三级菜单

时间:2019-09-21
本文章向大家介绍Python 21 三级菜单,主要包括Python 21 三级菜单使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
menu = {
    '北京':{
        '海淀':{
            '五道口':{
                'soho':{},
                '网易':{},
                'google':{}
            },
            '中关村':{
                '爱奇艺':{},
                '汽车之家':{},
                'youku':{}
            },
            '上地':{
                '百度':{}
            }
        },
        '昌平':{
            '沙河':{
                '老男孩':{},
                '北航':{},
            },
            '天通苑':{},
            '回龙观':{}
        },
        '朝阳':{},
        '东城':{}
    },
    '上海':{
        '闵行':{
            '人民广场':{
                '炸鸡店':{}
            }
        },
        '闸北':{
            '火车站':{
                '携程':{}
            }
        },
        '浦东':{}
    },
    '山东':{}
}


# l = [menu]
# while 1:
#     for key in l[-1]:
#         print(key)
#     k = input('input>>>:').strip()
#     if k in l[-1].keys() and l[-1][k]:
#         l.append(l[-1][k])
#     elif k == 'b':
#         l.pop()
#     elif k == 'q':break
#     else:continue




def threeLM(dic):
    while True:
        for k in dic:
            print(k)
        key = input('inmut>>>:').strip()
        if key == 'b' or key == 'q':
            return key
        elif key in dic.keys() and dic[key]:
            ret = threeLM(dic[key])
            if ret == 'q':
                return 'q'
        elif (not dic.get(key)) or (not dic[key]):
            continue

threeLM(menu)
三级菜单

原文地址:https://www.cnblogs.com/xiuyou/p/11561573.html