python之三級菜單

來源:互聯網
上載者:User

標籤:菜單   二級菜單   item   lower   input   color   退出   end   選擇   

 1 #-*- coding:utf-8 -*- 2  3 ‘‘‘******************************************************‘ 4                     三級菜單 5         1. 運行程式輸出第一級菜單 6         2. 選擇一級菜單某項,輸出二級菜單,同理輸出三級菜單 7         3. 返回上一級菜單和頂部菜單 8         4. 菜單資料儲存在檔案中" 9 ‘******************************************************‘‘‘10 11 import sys12 dic = {13     "北京":{14         "fa":{15             "aa":[123]16         },17         "li":{18             "bb":[122,332]19         }20     },21     "上海": {22         "浦東新區":{23             "金橋":["新金橋路","雲橋路"]24         },25         "普陀":{26             "dd":["s"]27         }28     }29 }30 31 32 file = open("menu.txt","w+",encoding=‘utf-8‘)33 34 lTmp = []35 while True:36     dTmp = dic37     for item in lTmp:38         if dTmp.get(item)!= None:39             dTmp = dTmp[item]40         else:41             print("您要尋找的菜單:%s不存在!"%lTmp[-1])42             lTmp.pop()43     print("當前的功能表項目有:", list(dTmp.keys()))44     choice = input("1、查看菜單節點,2、返回上一級(b/B),返回頂級菜單(t\T) 3、退出(q/Q)\n>>>")45     if choice == ‘1‘:46         name = input("請輸入您要查看的菜單\n>>>")47         lTmp.append(name)48     elif choice.lower() == ‘b‘ or choice.lower() == ‘t‘:49         if choice.lower() == ‘b‘:50             lTmp.pop()51         else:52             lTmp.clear()53     elif choice.lower() == ‘q‘:54         file.write(str(dic))55         file.close()56         sys.exit(1)57     else:58         print("很抱歉您的輸入有誤,請重新輸入!")

 

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.