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

來源:互聯網
上載者:User

標籤:googl   menu   ping   浦東   body   定義   表資料   nta   pen   

python三級菜單最佳化,菜鳥版連結:http://www.cnblogs.com/xuyaping/p/6648170.html

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 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三級菜單最佳化

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.