三級選單的實現
阿新 • • 發佈:2018-12-06
還是有不行的地方,先記錄一下,往下學習在繼續完善。
china = {'遼寧省':{'瀋陽':['和平區','太原街','中街'], '大連':['甘井子','瓦房店','金州區'], '朝陽':['朝陽縣','凌源','北票']}, '吉林省':{'蛟河':['新農','天北鎮','前進鄉'], '吉林':['永吉縣','豐滿區','龍潭區'], '長春':['朝陽區','綠園區','寬城區']}, }import time province = [] city = [] info = True while info: print("".center(13,"="),"歡迎使用","".center(13,"=")) print("".center(36,"=")) for key, value in enumerate(china.keys(),1): print(key,value) province.append(value) print("退出請按q") print("".center(36,"=")) number1= input("please entry your number:") print("".center(36, "=")) if number1 == 'q' or number1 == 'Q': exit() if number1.isdigit(): number1 = int(number1) if number1 <= len(province) and number1 > 0 : for key,value in enumerate(china[province[number1 - 1]].keys(),1):print(key,value) city.append(value) print("退出請按q或Q","返回上一級請按b或B") print("".center(36, "=")) number2 = input("please entry your number:") print("".center(36, "=")) if number2 == 'q' or number2 == 'Q': info = False elif number2 == 'b' or number2 == 'B': del province[:] del city[:] elif number2.isdigit(): number2 = int(number2) if number2 <= len(city) and number2 > 0 : while info: for name in china[province[number1 - 1]][city[number2 - 1]]: print(name) print("退出請按q或Q","返回上一級請按b或B") print("".center(36, "=")) number3 = input("please entry your number:") if number3 == 'q' or number3 == 'Q': info = False elif number3 == 'b' or number3 == 'B': del city[:] else: print("輸入錯誤!!") time.sleep(1) else: print("輸入錯誤!!") time.sleep(3)