三级菜单优化

 1 #Author:Archer Zon
 2 import time
 3 data = {
 4     '北京':{
 5         "朝阳":{
 6             "天河":{
 7                 "abc",
 8                 "bbc",
 9                 "CCTV",
10             },
11             "广埠屯":{},
12         },
13         "天安门":{},
14         "东直门":{},
15     },
16     '山东':{},
17     '广东':{},
18 }
19 exit_flag = False
20 while not exit_flag:
21     for i in data:
22         print(i)
23     choice = input("选择进入>>:")
24     if choice in data:
25         while not exit_flag:
26             for i2 in data[choice]:
27                 print(i2)
28             choice2 = input("选择进入>>:")
29             if choice2 in data[choice]:
30                 while not exit_flag:
31                     for i3 in data[choice][choice2]:
32                         print(i3)
33                     choice3 = input("选择进入>>:")
34                     if choice3 in data[choice][choice2]:
35                         for i4 in data[choice][choice2][choice3]:
36                             print(i4)
37                         choice4 = input("最后一层,按b返回!")
38                         if choice4 == 'b':
39                             pass
40                         elif choice4 == 'q':
41                             print("即将退出系统,请稍等...")
42                             time.sleep(2)
43                             exit_flag = True
44                     if choice3 == 'b':
45                         break
46                     elif choice3 =='q':
47                         print("即将退出系统,请稍等...")
48                         time.sleep(2)
49                         exit_flag = True
50             if choice2 == 'b':
51                 break
52             elif choice2 == 'q':
53                 print("即将退出系统,请稍等...")
54                 time.sleep(2)
55                 exit_flag =True
56     elif choice == 'q':
57         print("即将退出系统,请稍等...")
58         time.sleep(2)
59         exit_flag = True
60     else:
61         print("\033[31;1mvalid option!\033[0m")
View Code

猜你喜欢

转载自www.cnblogs.com/archerzon/p/9499491.html