1 1 # -*- coding: utf-8 -*- 2 2 # @Time : 2018-06-01 13:40 3 3 # @Author : 超人 4 4 # @Email : huxiaojiu111@gmail.com 5 5 # @File : 简单实现多级菜单功能 (输入s返回首菜单,输入b返回上一菜单,输入o终止程序) 6 6 # @Software: PyCharm 7 7 8 8 current_layer = menu#字典,多级菜单 9 9 parent_layers=[] 1010 while True: 1111 for key in current_layer: 1212 print(key) 1313 choice = input('>>>>>>>>>>>').strip() 1414 if len(choice) == 0: continue 1515 if choice in current_layer: 1616 # print(choice) 1717 parent_layers.append(current_layer) 1818 current_layer = current_layer[choice] 1919 elif choice == "b": 2020 if not len(parent_layers)==0: 2121 current_layer = parent_layers.pop() 2222 else: 2323 current_layer=menu 2424 elif choice =="s": 2525 current_layer = menu 2626 elif choice == "o": 2727 break 2828 else: 2929 print('没有此选项,重新输入'.center(50,"-"))
Python简单实现多级菜单
Stella981
2021-10-12
995 0 0
点赞
收藏
评论区
加载中...