编写三级菜单: 1. 运行程序输出第一级菜单 2. 选择一级菜单某项,输出二级菜单,同理输出三级菜单 3. 菜单数据保存在文件中 4. 让用户选择是否要退出 5. 有返回上一级菜单的功能
1 # Author: zfh 2 3 data = { 4 "陕西":{ 5 "汉中":["张骞故里","古汉台"], 6 "西安":[], 7 "商洛":[] 8 }, 9 "山西":{10 "太远":[],11 "运城":[],12 "平凉":[]13 },14 "山东":{15 "青岛":[],16 "济南":[],17 "聊城":[]18 }19 }20 exit_flag = False21 while not exit_flag:22 for i in data:23 print(i)24 choice = input("请输入选择1>>:")25 if choice in data:26 while not exit_flag:27 for i1 in data[choice]:28 print("\t",i1)29 choice1 = input("请输入选择2>>:")30 if choice1 in data[choice]:31 while not exit_flag:32 for i2 in data[choice][choice1]:33 print("\t\t",i2)34 choice2 = input("最后一层,按b返回>>:")35 if choice2 == "b":36 pass37 elif choice2 == "q":38 exit_flag = True39 if choice1 == "b":40 break41 elif choice1 == "q":42 exit_flag = True43 if choice == "b":44 break45 elif choice =="q":46 exit_flag = True