多级菜单的实现
Posted Mrchan9
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了多级菜单的实现相关的知识,希望对你有一定的参考价值。
利用字典实现多级菜单:
area = { ‘广西‘:{ ‘梧州‘:{ ‘岑溪‘:[‘豆腐酿‘,‘新圩米粉‘,‘茄子酿‘,‘白切鸡‘], ‘容县‘:[‘1‘,‘2‘,‘3‘], ‘苍梧‘:[‘4‘,‘5‘,‘6‘] }, ‘南宁‘:{ ‘武鸣区‘:[‘大明山‘,‘伊岭岩‘,‘灵水‘,‘明秀园‘], ‘宾阳县‘:[‘鱼生‘,‘宾阳酸辣粉‘] } }, ‘广东‘:{ ‘广州市‘:[‘越秀区‘,‘荔湾区‘,‘‘], ‘深圳市‘:[‘福田区‘,‘罗湖区‘,‘宝安区‘], ‘珠海市‘:[‘香洲区‘,‘斗门区‘,‘金湾区‘] }, ‘湖南‘:{ ‘长沙市‘:[‘长沙县‘,‘宁乡县‘,‘雨花区‘], ‘湘潭市‘:[‘雨湖区‘,‘湘潭县‘,‘韶山市‘], ‘娄底市‘:[‘娄星区‘,‘新化县‘,‘双峰县‘] } } while True: for i in area: print(i) choice = input(‘\n请输入地方名:‘) if choice in area: while True: for i2 in area[choice]: print(‘\t‘,i2) choice2 = input(‘\n请输入地方名:‘) if choice2 in area[choice]: while True: for i3 in area[choice][choice2]: print(‘\t\t‘,i3) choice3 = input(‘\n请输入地方名:‘) if choice3 in area[choice][choice2]: for i4 in area[choice][choice2][choice3]: print(‘\t\t\t‘,i4) choice4 = input(‘\n没有啦,按回车返回上一级:‘) if choice4 == ‘b‘: pass elif choice4 == ‘q‘: exit() if choice3 == ‘b‘: break elif choice3 == ‘q‘: exit() if choice2 == ‘b‘: break elif choice2 == ‘q‘: exit() if choice == ‘q‘: exit()
以上是关于多级菜单的实现的主要内容,如果未能解决你的问题,请参考以下文章