Posted in Python onMarch 12, 2019
本文实例讲述了Python3实现的简单三级菜单功能。分享给大家供大家参考,具体如下:
三级菜单_要求:
1. 运行程序输出第一级菜单
2. 选择一级菜单某项,输出二级菜单,同理输出三级菜单
3. 菜单数据保存在文件中
4. 让用户选择是否要退出
5. 有返回上一级菜单的功能
执行代码:
#!/usr/bin/env python3 # Author:Robert # --*-- coding: utf-8 --*-- data = { "北京":{ "东城区":{ "安定门":["国子监大街","孔庙","钟楼"], "建国门":["Jinbaojie","长安街","西街"], "朝阳门":["东四南大街","朝阳门内大街","孚王府"] }, "朝阳区":{ "和平街":["胜古庄社区","樱花社区","和平东街社区"], "八里庄":["慈寿寺塔","定慧寺"], "三里屯":["798艺术区","北京工人体育馆"] }, "海淀":{} }, '山东':{ "德州":{}, "青岛":{}, "济南":{} }, '广东':{ "东莞":{}, "常熟":{}, "佛山":{} } } exit_flag = False while not exit_flag: for i in data: print(i) choice = input("选择进入-->:") if choice in data: while not exit_flag: for i2 in data[choice]: print("\t",i2) choice2 = input("选择进入2-->:") if choice2 in data[choice]: while not exit_flag: for i3 in data[choice][choice2]: print("\t\t",i3) choice3 = input("选择进入3-->:") if choice3 in data[choice][choice2]: for i4 in data[choice][choice2][choice3]: print("\t\t",i4) choice4 = input("最后一层,按b返回-->:") if choice4 == "b": pass elif choice4 == "q": exit_flag = True if choice3 == "b": break elif choice4 == "q": exit_flag = True if choice2 == "b": break elif choice4 == "q": exit_flag = True
运行效果:
Python3实现的简单三级菜单功能示例
- Author -
爱跳舞的青年君声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@