1 # -*- coding: utf-8 -*- 2 # @Time : 2018-06-01 13:40 3 # @Author : 超人 4 # @Email : huxiaojiu111@gmail.com 5 # @File : 简单实现多级菜单功能 (输入s返回首菜单,输入b返回上一菜单,输入o终止程序) 6 # @Software: PyCharm 7 8 current_layer = menu#字典,多级菜单 9 parent_layers=[] 10 while True: 11 for key in current_layer: 12 print(key) 13 choice = input('>>>>>>>>>>>').strip() 14 if len(choice) == 0: continue 15 if choice in current_layer: 16 # print(choice) 17 parent_layers.append(current_layer) 18 current_layer = current_layer[choice] 19 elif choice == "b": 20 if not len(parent_layers)==0: 21 current_layer = parent_layers.pop() 22 else: 23 current_layer=menu 24 elif choice =="s": 25 current_layer = menu 26 elif choice == "o": 27 break 28 else: 29 print('没有此选项,重新输入'.center(50,"-"))