標籤:菜單 二級菜單 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之三級菜單