本文实例讲述了python3实现的简单三级菜单功能。分享给大家供大家参考,具体如下:
三级菜单_要求:
1. 运行程序输出第一级菜单
2. 选择一级菜单某项,输出二级菜单,同理输出三级菜单
3. 菜单数据保存在文件中
4. 让用户选择是否要退出
5. 有返回上一级菜单的功能
执行代码:
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
|
#!/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
|
运行效果:
希望本文所述对大家python程序设计有所帮助。
原文链接:https://blog.csdn.net/weixin_39099836/article/details/78388959