python3三级菜单的访问,并按q退出
程序员文章站
2022-03-18 16:53:14
#/usr/bin/env python#yehui'''作业三:多级菜单 三级菜单 可依次选择进入各子菜单 所需新知识点:列表、字典'''import readlineclass MultiLevelMenu: def __init__(self): self.counts = 0 self.mu ......
#/usr/bin/env python
#yehui
'''
作业三:多级菜单
三级菜单
可依次选择进入各子菜单
所需新知识点:列表、字典
'''
import readline
class MultiLevelMenu:
def __init__(self):
self.counts = 0
self.multi_level_menu = {
"这是第三级菜单!hello": {
"这是第二级菜单!hi": "这是第一级菜单"
}
}
for self.k3,self.v in self.multi_level_menu.items():
self.menu3 = self.k3
for self.k2,self.v1 in self.v.items():
self.menu2 = self.k2
self.menu1 = self.v1
def choice_menu(self):
print("1.%5s" % self.menu1)
print("2.%5s" % self.menu2)
print("3.%5s" % self.menu3)
while self.counts <= 10:
self.counts += 1
self.choic = input("请输入你想进入的菜单序列号,输入q退出: ")
if self.choic == "1":
print("欢迎进入一级菜单: %s" % self.menu1)
elif self.choic == "2":
print("欢迎进入二级菜单: %s" % self.menu2)
elif self.choic == "3":
print("欢迎进入三级菜单: %s" % self.menu3)
elif self.choic == "q":
exit("bye!")
if __name__ == '__main__':
m = MultiLevelMenu()
m.choice_menu()