Python——三级菜单

#三级菜单函数
menu = {
    '北京':{
        海淀:{
            '五道口':{}
            '中关村':{}
            '上帝':{}
        }
        '昌平':{}
        '朝阳':{}
        '东城':{}
    },
    '上海':{}
    '山东':{}
}    
def threeMe(dic):
    while True:
        for k in dic:
            print(k)
        key = input('imput>>').strip()
        if key == 'b' or key == 'q':
            return
        elif key in dic.keys() and dic[key]:
            ret = threeMe(dic[key])
            if ret == 'q':
                return
        elif (not dic.get(key) or (not dic[key]):
            continue

threeMe(menu)

 

posted @ 2018-10-09 15:47  澄心元素  阅读(648)  评论(0编辑  收藏  举报