三级菜单的实现
还是有不行的地方,先记录一下,往下学习在继续完善。
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)