三级菜单

Posted 沧海一粒水

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了三级菜单相关的知识,希望对你有一定的参考价值。

#Author:xiesongyou

China= {
‘山东‘ : {
‘青岛‘ : [‘四方‘,‘黄岛‘,‘崂山‘,‘李沧‘,‘城阳‘],
‘济南‘ : [‘历城‘,‘槐荫‘,‘高新‘,‘长青‘,‘章丘‘],
‘烟台‘ : [‘龙口‘,‘莱山‘,‘牟平‘,‘蓬莱‘,‘招远‘]
},
‘江苏‘ : {
‘苏州‘ : [‘沧浪‘,‘相城‘,‘平江‘,‘吴中‘,‘昆山‘],
‘南京‘ : [‘白下‘,‘秦淮‘,‘浦口‘,‘栖霞‘,‘江宁‘],
‘无锡‘ : [‘崇安‘,‘南长‘,‘北塘‘,‘锡山‘,‘江阴‘]
},
‘浙江‘ : {
‘杭州‘ : [‘西湖‘,‘江干‘,‘下城‘,‘上城‘,‘滨江‘],
‘宁波‘ : [‘海曙‘,‘江东‘,‘江北‘,‘镇海‘,‘余姚‘],
‘温州‘ : [‘鹿城‘,‘龙湾‘,‘乐清‘,‘瑞安‘,‘永嘉‘]
},
‘安徽‘ : {
‘合肥‘ : [‘蜀山‘,‘庐阳‘,‘包河‘,‘经开‘,‘新站‘],
‘芜湖‘ : [‘镜湖‘,‘鸠江‘,‘无为‘,‘三山‘,‘南陵‘],
‘蚌埠‘ : [‘蚌山‘,‘龙子湖‘,‘淮上‘,‘怀远‘,‘固镇‘]
},
‘广东‘ : {
‘深圳‘ : [‘罗湖‘,‘福田‘,‘南山‘,‘宝安‘,‘布吉‘],
‘广州‘ : [‘天河‘,‘珠海‘,‘越秀‘,‘白云‘,‘黄埔‘],
‘东莞‘ : [‘莞城‘,‘长安‘,‘虎门‘,‘万江‘,‘大朗‘]
}
}

exit_flag = False
while not exit_flag:
print("省".center(50,‘-‘))
for index,province in enumerate(China):
print(index+1,":",province)
choice_province=input("请选择省编号(输入q退出):")
province_list = list(China.keys())
if choice_province.isdigit():
choice_province = int (choice_province)
if choice_province > 0 and choice_province <= len(province_list):
while not exit_flag :
print("市".center(50, ‘-‘))
province_name=province_list[choice_province - 1]
city = list(China[province_name].keys())
for c in city:
print(city.index(c) + 1, c)
choice_city = input("请选择市(b返回上级菜单,或输入q退出):")
if choice_city.isdigit():
choice_city = int(choice_city)
if choice_city > 0 and choice_city <= len(city):
while not exit_flag:
print("县".center(50, ‘-‘))
city_name = city[choice_city - 1]
country_name = list(China[province_name][city_name])
for ctry in country_name:
print(country_name.index(ctry) + 1, ctry)
country_choice = input("请选择县(b返回上级菜单,或输入q退出):")
if country_choice.isdigit():
country_choice = int(country_choice)
if country_choice > 0 and country_choice <= len(country_name):
print("你的选择是:",province_name,city_name,country_name[country_choice-1])
exit_flag = True
else:
print("输入错误序号!")
elif country_choice == "q":
exit_flag = True
elif country_choice == "b":
break
else:
print("输入序号错误!")
elif choice_city == ‘q‘:
exit_flag = True
elif choice_city == ‘b‘:
break
else:
print("输入序号错误!")
elif choice_province == ‘q‘:
exit_flag = True

以上是关于三级菜单的主要内容,如果未能解决你的问题,请参考以下文章

python-三级菜单和购物车程序代码(补发)

TreeUtils工具类一行代码实现列表转树 实战Java8 三级菜单 三级分类 附视频

1-2 三级菜单

Python 三级菜单

代码段-- 三级菜单 (基础版)

三级菜单-2018.2.21