本文实例为大家分享了Python三级菜单展示的具体代码,供大家参考,具体内容如下
作业需求:
(1)运行程序输出第一级菜单
(2)选择一级菜单某项,输出二级菜单,同理输出三级菜单
(3)让用户选择是否要退出
(4)有返回上一级菜单的功能
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
data = { "天津" :{ "南开区" :{ "南开大学" :{ "历史系" :{}, "文学系" :{}, "英语系" :{}, }, "科技大学" :{ "计算机系" :{}, "机器系" :{}, "软件系" :{}, }, "理工大学" :{ "数学系" :{}, "化学系" :{}, "物理系" :{}, }, }, "武清区" :{ "武清大学" :{ "历史系" :{}, "文学系" :{}, "英语系" :{}, }, "武清科技大学" :{ "计算机系" :{}, "机器系" :{}, "软件系" :{}, }, "武清理工大学" :{ "数学系" :{}, "化学系" :{}, "物理系" :{}, }, }, "北辰区" :{ "北辰大学" :{ "历史系" :{}, "文学系" :{}, "英语系" :{}, }, "北辰科技大学" :{ "计算机系" :{}, "机器系" :{}, "软件系" :{}, }, "北辰理工大学" :{ "数学系" :{}, "化学系" :{}, "物理系" :{}, }, }, }, "河北" :{ "保定市" : { "保定大学" : { "历史系" : {}, "文学系" : {}, "英语系" : {}, }, "保定科技大学" : { "计算机系" : {}, "机器系" : {}, "软件系" : {}, }, "保定理工大学" : { "数学系" : {}, "化学系" : {}, "物理系" : {}, }, }, "秦皇岛" : { "秦皇岛大学" : { "历史系" : {}, "文学系" : {}, "英语系" : {}, }, "秦皇岛科技大学" : { "计算机系" : {}, "机器系" : {}, "软件系" : {}, }, "秦皇岛理工大学" : { "数学系" : {}, "化学系" : {}, "物理系" : {}, }, }, "石家庄" : { "石家庄大学" : { "历史系" : {}, "文学系" : {}, "英语系" : {}, }, "石家庄科技大学" : { "计算机系" : {}, "机器系" : {}, "软件系" : {}, }, "石家庄理工大学" : { "数学系" : {}, "化学系" : {}, "物理系" : {}, }, }, }, "河南" :{ "郑州市" : { "郑州大学" : { "历史系" : {}, "文学系" : {}, "英语系" : {}, }, "郑州科技大学" : { "计算机系" : {}, "机器系" : {}, "软件系" : {}, }, "郑州理工大学" : { "数学系" : {}, "化学系" : {}, "物理系" : {}, }, }, "南阳市" : { "南阳大学" : { "历史系" : {}, "文学系" : {}, "英语系" : {}, }, "南阳科技大学" : { "计算机系" : {}, "机器系" : {}, "软件系" : {}, }, "南阳理工大学" : { "数学系" : {}, "化学系" : {}, "物理系" : {}, }, }, "登封市" : { "登封大学" : { "历史系" : {}, "文学系" : {}, "英语系" : {}, }, "登封科技大学" : { "计算机系" : {}, "机器系" : {}, "软件系" : {}, }, "登封理工大学" : { "数学系" : {}, "化学系" : {}, "物理系" : {}, }, }, }, } #exit_flag = False while True : for i in data : print (i) choice = input ( "input:" ) if choice in data: while True : for i2 in data[choice]: print (i2) choice2 = input ( "input2:" ) if choice2 in data[choice]: while True : for i3 in data[choice][choice2]: print (i3) choice3 = input ( "input3:" ) if choice3 in data[choice][choice2]: for i4 in data[choice][choice2][choice3]: print (i4) choice4 = input ( "Press b to return to the previous level:" ) if choice4 = = "b" : pass elif choice4 = = "q" : exit () if choice3 = = "b" : break elif choice3 = = "q" : exit() if choice2 = = "b" : break elif choice2 = = "q" : exit() |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。