pathon作业:字典、列表、字符串应用实例-打印三级菜单小程序
打印省市县三级菜单,输入‘q’退出程序,否则循环执行。
''' application of dictionary,list,and string ''' dic = {'Jilin province':{'Songyuan':['Fuyu','Qianguo'], 'Baicheng':['Daan','Taonan']}, 'LiaoNin Province':{'Shenyang':['A','B'], 'Dalian':['C','D']}, 'Heilongjiang Province':{'Haerbin':['E','F'], 'Mudanjiang':['G','H']} } while True: print("province name".center(50, '-')) province_name = [] for i in dic: print(i) province_name.append(i) choice = input("input your choice:") province_index_name = province_name[int(choice)] print("city name".center(50,'-')) city_name = [] for j in dic[province_index_name]: print(j) city_name.append(j) choice = input("please input your choice:") city_index_name = city_name[int(choice)] print("county name".center(50,'-')) for k in dic[province_index_name][city_index_name]: print(k) selection = input("q/quit or return to the list") if selection == 'q': exit("bye-bye")