Output the Level 3 menu, select it, and display it layer by layer. "B" returns to the level 1 menu.
Menu = {'Beijing': {'haidian ': {'wudaokou': {'Soho ':{}, 'netease' :{}, 'Google ':{}}, 'Zhongguancun ': {'iqiyi' :{}, 'car home' :{}, 'youku ':{},}, 'upgrade': {'Baidu ': {},}}, 'changping ': {'shahe': {'old boys' :{}, 'beihang ':{},}, 'tiantongyuan ':{}, 'longguan ':{},}, 'chaoyang' :{}, 'dongcheng ':{},}, 'Shanghai': {'minhang': {"People's Square ": {'Fried Chicken Shop ':{}}, 'zhabei': {'train barri': {'ctrip ':{}}, 'pudong ':{},}, 'Shandong ':{},}
Second Force youth edition:
while True: for key in menu: print(key) choice = input(">>>:") if len(choice) == 0: continue if choice not in menu:continue while True: for key2 in menu[choice]: print(key2) choice2 = input(">>>:") if len(choice2) == 0: continue if choice2 == "b": break if choice2 not in menu[choice]: continue while True: for key3 in menu[choice][choice2]: print(key3) choice3 = input(">>>:") if len(choice3) == 0: continue if choice3 == "b": break if choice3 not in menu[choice][choice2]: continue while True: for key4 in menu[choice][choice2][choice3]: print(key4) choice4 = input(">>>:") if len(choice4) == 0: continue if choice4 == "b": break if choice4 not in menu[choice][choice2][choice3]: continue
Youth Edition:
current_level = menulast_level = []while True: for key in current_level: print(key) choice = input(">>>:") if len(choice) == 0:continue if choice == "b": if not last_level : break current_level = last_level[-1] last_level.pop() if choice not in current_level:continue last_level.append(current_level) current_level = current_level[choice]
By terry
Blog: http://www.cnblogs.com/kkterry/
Weaver: http://weibo.com/kkterry
E-mail: doubleginger@163.com
You are welcome to reprint it. please also indicate the source! Thank you!