python---三级菜单

  三级菜单,比较low级别的,后续学习函数调用

 1 # -*- coding:utf-8 -*-
 2 # LC
 3 data = {
 4     "浙江省":{
 5         "杭州市":{
 6             "西湖区":["西湖","黄龙"],
 7             "余杭区":["西溪银泰","闲湖"],
 8             "滨江区":["星光大道","垃圾街"]
 9         },
10         "温州市":{
11             "瓯海区":["温州大学","茶山"],
12             "苍南":["金乡","灵溪"]
13         },
14         "台州":{
15             "路桥":["海鲜","喷雾器"],
16             "温岭":["高山","绿叶"]
17         }
18     },
19     "广东省":{
20         "广州市"
21     }
22 }
23 
24 exit_flag = True
25 
26 while exit_flag:
27     for i in data:
28         print(i)
29     choice = input("请选择1>>>:")                  #选择省
30     if choice in data:
31         while exit_flag:
32             for j in data[choice]:
33                 print(j)
34             choice2 = input("请选择2,返回上一层请按b,退出请按q>>>:")         #选择市
35             if choice2 in data[choice]:
36                 while exit_flag:
37                     for k in data[choice][choice2]:
38                         print(k)
39                     choice3 = input("请选择3,返回上一层请按b,退出请按q>>>:")     #选择区
40                     if  choice3 in data[choice][choice2]:
41                         for l in data[choice][choice2][choice3]:
42                             print(l)
43                         choice4 = input("最后一层,返回上一层请按b,退出请按q>>>:")
44                         if choice4 == "b":
45                             break
46                         elif choice4 == "q":
47                             exit_flag = False
48                     elif choice3 == "b":            #如果选择返回,则中断此次循环
49                         break
50                     elif choice3 == "q":            #如果选择退出,则将循环值改为False,所有循环结束,退出
51                         exit_flag = False
52                     else:
53                         print("选择有误,重新输入!")
54                         continue
55             elif choice2 == "b":
56                 break
57             elif choice2 == "q":
58                 exit_flag = False
59             else:
60                 print("选择有误,重新输入!")
61                 continue

 

posted on 2017-06-16 00:33  clv  阅读(196)  评论(0编辑  收藏  举报

导航