Category:随笔小练习
Article From:https://www.cnblogs.com/chaoren-hu/p/9122602.html
 1 # -*- coding: utf-8 -*-
 2 # @Time    : 2018-06-01 13:40
 3 # @Author  : superman
 4 # @Email   : huxiaojiu111@gmail.com
 5 # @File    : Simple realization of multi-level menu function (input s return to the first menu, input B return to the previous menu, enter o termination procedure)
 6 # @Software: PyCharm
 7 
 8 current_layer = menu#Dictionaries, multilevel menus
 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('Without this option, re - enter'.center(50,"-"))

 

Leave a Reply

Your email address will not be published. Required fields are marked *