编程语言
首页 > 编程语言> > Python--字典(三级菜单)

Python--字典(三级菜单)

作者:互联网

 1 # -*- coding:utf-8 -*-
 2 
 3 data = {
 4     "腾讯":{
 5         "LOL":{
 6             "上单":["诺手","剑姬","蛮王"],
 7             "打野":["男枪","盲僧","卡兹克"]
 8         },
 9         "CF":{
10             "步枪":[],
11             "手枪":[],
12             "机枪":[]
13         },
14         "王者":{
15             "上单":["宫本","亚瑟","项羽"],
16             "打野":["李白","兰陵王","韩信"],
17             "射手":["鲁班","后裔"]
18         }
19     },
20     "网易":{
21         "游戏1"
22     }
23 }
24 
25 exit_flag = False
26 while not exit_flag:
27     for i1 in data:
28         print(i1)
29     choice1 = input(">>>1:")
30     if choice1 in data:
31         while not exit_flag:
32             for i2 in data[choice1]:
33                 print("\t",i2)
34             choice2 = input(">>>2:")
35             if choice2 in data[choice1]:
36                 while not exit_flag:
37                     for i3 in data[choice1][choice2]:
38                         print("\t\t",i3)
39                     choice3 = input(">>>3:")
40                     if choice3 in data[choice1][choice2]:
41                         for i4 in data[choice1][choice2][choice3]:
42                             print(i4)
43                         choice4 = input(">>>4:")
44                         if choice4 == "b":
45                             pass
46                         elif choice4 == "q":
47                             exit_flag = True
48                     elif choice3 == "b":
49                         break
50                     elif choice3 == "q":
51                         exit_flag = True
52             elif choice2 == "b":
53                 break
54             elif choice2 == "q":
55                 exit_flag = True
56     elif choice1 == "q":
57         exit_flag = True

标签:elif,菜单,Python,choice1,choice2,flag,exit,data,字典
来源: https://www.cnblogs.com/sunnytomorrow/p/12945949.html