最简三级菜单

可按b返回,按q退出

menu = {

'北京':{

    '海淀':{

        '五道口':{

            'soho':{},

            '网易':{},

            'google':{}

        },

        '中关村':{

            '爱奇艺':{},

            '汽车之家':{},

            'youku':{},

        },

        '上地':{

            '百度':{},

        },

    },

    '昌平':{

        '沙河':{

            '老男孩':{},

            '北航':{},

        },

        '天通苑':{},

        '回龙观':{},

    },

    '朝阳':{},

    '东城':{},

},

'上海':{

    '闵行':{

        "人民广场":{

            '炸鸡店':{}

        }

    },

    '闸北':{

        '火车战':{

            '携程':{}

        }

    },

    '浦东':{},

},

'山东':{},

}


last_layer = [menu,]
while True:
    if len(last_layer) == 0:last_layer = [menu,]
    cureent_layer = last_layer[-1]
    if len(cureent_layer) == 0: print("这是最后一层了!返回b|退出q")
    for i in cureent_layer:
        print(i)
    choice = input(">>>").strip()
    if not choice:continue
    if choice in cureent_layer:
        last_layer.append(cureent_layer[choice])
    if choice == "q":
        break
    if choice == "b":
        last_layer.pop(-1)
posted on 2018-08-06 20:29  summer-rain  阅读(130)  评论(0编辑  收藏  举报