代码段-- 三级菜单 (基础版)
Posted 盛欣
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了代码段-- 三级菜单 (基础版)相关的知识,希望对你有一定的参考价值。
# __author__:"ShengXin" # __date__:2017/8/24 full_menu = {‘河北省‘:{‘张家口市‘:[‘蔚县‘,‘涿鹿县‘,‘怀来县‘,‘阳原县‘], ‘唐山市‘:[‘丰润区‘,‘滦县‘,‘开平区‘,‘玉田县‘], ‘衡水市‘:[‘武邑县‘,‘武强县‘,‘枣强县‘,‘市辖区‘] }, ‘山西省‘:{‘太原市‘:[‘A‘,‘B‘,‘C‘,‘D‘], ‘大同市‘:[‘AA‘,‘BB‘,‘CC‘,‘DD‘], ‘吕梁市‘:[‘AAA‘,‘BBB‘,‘CCC‘,‘DDD‘] }, ‘河南省‘:{‘郑州市‘:[‘W‘,‘E‘,‘R‘,‘T‘], ‘开封市‘:[‘WW‘,‘EE‘,‘RR‘,‘TT‘], ‘洛阳市‘:[‘WWW‘,‘EEE‘,‘RRR‘,‘TTT‘] } } town = [] county = [] flag_one = True while flag_one: flag_two = True print("欢迎来到德莱联盟,请选择您想加入的省:".center(30,"-")) for i in full_menu: #遍历键 print(i) choose = input("您选择:") if choose in full_menu: while flag_two: print("%s".center(30,"-")%choose) for j in full_menu[choose]: #市区 print(j) town.append(j) flag_two = True flag_three =True small_choose = input("选择您感兴趣的市,b返回,q退出") if small_choose in town: while flag_three: print("%s".center(30,"-")%small_choose) hah = ((full_menu[choose])[small_choose]) for e in hah: print(e) county.append(e) flag_three =True flag_four = True least_choose = input("请选择您喜欢的县,b返回,q退出") if least_choose in county: while flag_four: flag_four =True print("\n"+least_choose+"欢迎您") man = input("您可按b继续选择县,按q选择市,按w退出") if man == "b": flag_four =False elif man == "q": flag_four = False flag_three = False elif man == "w": flag_four = False flag_three = False flag_two = False if least_choose == "b": break elif least_choose == "q": flag_two =False break elif least_choose == "w": flag_one =False flag_two =False break elif small_choose == "b": break elif small_choose == "q": flag_two = False else: print("请重新输入,或按b返回") elif choose == "q": print("再见") flag_one = False else: print("请重新输入,或按q退出")
以上是关于代码段-- 三级菜单 (基础版)的主要内容,如果未能解决你的问题,请参考以下文章