Python簡單實現多級菜單


 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,"-"))

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM