1. 程式人生 > >python(5)- 簡單練習:python三級菜單優化

python(5)- 簡單練習:python三級菜單優化

blog 三級 cells lsp http x11 cin while 山東

python三級菜單優化,菜鳥版鏈接:http://www.cnblogs.com/xuyaping/p/6648170.html

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 menu = { ‘北京‘:{ ‘海澱‘:{ ‘五道口‘:{
‘soho‘:{}, ‘網易‘:{}, ‘google‘:{} }, ‘中關村‘:{ ‘愛奇藝‘:{}, ‘汽車之家‘:{}, ‘youku‘:{}, }, ‘上地‘:{ ‘百度‘:{}, }, }, ‘昌平‘:{ ‘沙河‘:{
‘北航‘:{}, }, ‘天通苑‘:{}, ‘回龍觀‘:{}, }, ‘朝陽‘:{}, ‘東城‘:{}, }, ‘上海‘:{ ‘閔行‘:{ "人民廣場":{ ‘炸雞店‘:{} } }, ‘閘北‘:{ ‘火車戰‘:{ ‘攜程‘:{} } },
‘浦東‘:{}, }, ‘山東‘:{}, } current_layer=menu #當前層 last_layers=[menu] #上一層 while True: for key in current_layer: #打印第一層菜單 print(key) choice=input(">>:").strip() #選擇第二層菜單 if choice in current_layer: last_layers.append(current_layer) #進入下一層菜單前,把當前層菜單加入上一次菜單中 current_layer=current_layer[choice] #當前層菜單被重新定義,進入循環打印下一層菜單 if choice==0: #選擇菜單層為空,結束本次循環 continue if choice=="q": #選擇菜單層為“q”,結束本層循環 break if choice=="b": #選擇菜單層為“b”,返回上一層菜單 current_layer=last_layers[-1] #返回上一層菜單前,當前層被重新定義 last_layers.pop() #刪除最後一次進入下一層菜單所加入的上一層列表數據 print("程序結束!")

  

python(5)- 簡單練習:python三級菜單優化