day2-三級菜單---改良版
阿新 • • 發佈:2018-06-28
進入 type bsp day lower style div 退出 ice
再也不想看之前的low代碼了。。。
#!/usr/bin/env python data = { ‘北京‘: { "昌平": { "望京1": {"奔馳", "默默"}, "國貿2": ("cicc", "HP"), }, "朝陽": { "望京1": {"奔馳", "默默"}, "國貿1": ("cicc", "HP"), }, }, ‘山東‘: { "昌平": { "望京1": {"奔馳", "默默"}, "國貿2": ("cicc", "HP"), }, "朝陽": { "望京2": {"奔馳", "默默"}, "國貿2": ("cicc", "HP"), }, }, ‘廣東‘: { "昌平": { "望京1": {"奔馳", "默默"}, "國貿2": ("cicc", "HP"), }, "朝陽": {"望京3": {"奔馳", "默默"}, "國貿4": ("cicc", "HP"), }, }, } current_layer = data layerlist = list() while True: for i in current_layer: print(i) choice = input("選擇進入,按b返回,按q退出>>:") if choice in current_layer: try: layerlist.append(current_layer) current_layer= current_layer[choice] except TypeError: current_layer = current_layer continue elif choice.lower() == ‘b‘: try: current_layer = layerlist.pop() except IndexError: pass continue elif choice.lower() == ‘q‘: exit("bye~~")
day2-三級菜單---改良版