标签:菜单 选择 choice ret 返回 ice http data exit
作业需求:
(1)运行程序输出第一级菜单
(2)选择一级菜单某项,输出二级菜单,同理输出三级菜单
(3)让用户选择是否要退出
(4)有返回上一级菜单的功能
1 data = { 2 "天津":{ 3 "南开区":{ 4 "南开大学":{ 5 "历史系":{}, 6 "文学系":{}, 7 "英语系":{}, 8 }, 9 "科技大学":{ 10 "计算机系":{}, 11 "机器系":{}, 12 "软件系":{}, 13 }, 14 "理工大学":{ 15 "数学系":{}, 16 "化学系":{}, 17 "物理系":{}, 18 }, 19 }, 20 "武清区":{ 21 "武清大学":{ 22 "历史系":{}, 23 "文学系":{}, 24 "英语系":{}, 25 }, 26 "武清科技大学":{ 27 "计算机系":{}, 28 "机器系":{}, 29 "软件系":{}, 30 }, 31 "武清理工大学":{ 32 "数学系":{}, 33 "化学系":{}, 34 "物理系":{}, 35 }, 36 }, 37 "北辰区":{ 38 "北辰大学":{ 39 "历史系":{}, 40 "文学系":{}, 41 "英语系":{}, 42 }, 43 "北辰科技大学":{ 44 "计算机系":{}, 45 "机器系":{}, 46 "软件系":{}, 47 }, 48 "北辰理工大学":{ 49 "数学系":{}, 50 "化学系":{}, 51 "物理系":{}, 52 }, 53 }, 54 }, 55 "河北":{ 56 "保定市": { 57 "保定大学": { 58 "历史系": {}, 59 "文学系": {}, 60 "英语系": {}, 61 }, 62 "保定科技大学": { 63 "计算机系": {}, 64 "机器系": {}, 65 "软件系": {}, 66 }, 67 "保定理工大学": { 68 "数学系": {}, 69 "化学系": {}, 70 "物理系": {}, 71 }, 72 }, 73 "秦皇岛": { 74 "秦皇岛大学": { 75 "历史系": {}, 76 "文学系": {}, 77 "英语系": {}, 78 }, 79 "秦皇岛科技大学": { 80 "计算机系": {}, 81 "机器系": {}, 82 "软件系": {}, 83 }, 84 "秦皇岛理工大学": { 85 "数学系": {}, 86 "化学系": {}, 87 "物理系": {}, 88 }, 89 }, 90 "石家庄": { 91 "石家庄大学": { 92 "历史系": {}, 93 "文学系": {}, 94 "英语系": {}, 95 }, 96 "石家庄科技大学": { 97 "计算机系": {}, 98 "机器系": {}, 99 "软件系": {}, 100 }, 101 "石家庄理工大学": { 102 "数学系": {}, 103 "化学系": {}, 104 "物理系": {}, 105 }, 106 }, 107 }, 108 "河南":{ 109 "郑州市": { 110 "郑州大学": { 111 "历史系": {}, 112 "文学系": {}, 113 "英语系": {}, 114 }, 115 "郑州科技大学": { 116 "计算机系": {}, 117 "机器系": {}, 118 "软件系": {}, 119 }, 120 "郑州理工大学": { 121 "数学系": {}, 122 "化学系": {}, 123 "物理系": {}, 124 }, 125 }, 126 "南阳市": { 127 "南阳大学": { 128 "历史系": {}, 129 "文学系": {}, 130 "英语系": {}, 131 }, 132 "南阳科技大学": { 133 "计算机系": {}, 134 "机器系": {}, 135 "软件系": {}, 136 }, 137 "南阳理工大学": { 138 "数学系": {}, 139 "化学系": {}, 140 "物理系": {}, 141 }, 142 }, 143 "登封市": { 144 "登封大学": { 145 "历史系": {}, 146 "文学系": {}, 147 "英语系": {}, 148 }, 149 "登封科技大学": { 150 "计算机系": {}, 151 "机器系": {}, 152 "软件系": {}, 153 }, 154 "登封理工大学": { 155 "数学系": {}, 156 "化学系": {}, 157 "物理系": {}, 158 }, 159 }, 160 }, 161 } 162 #exit_flag = False 163 while True: 164 for i in data : 165 print (i) 166 choice = input ("input:") 167 if choice in data: 168 while True: 169 for i2 in data[choice]: 170 print (i2) 171 choice2 = input("input2:") 172 if choice2 in data[choice]: 173 while True: 174 for i3 in data[choice][choice2]: 175 print (i3) 176 choice3 = input("input3:") 177 if choice3 in data[choice][choice2]: 178 for i4 in data[choice][choice2][choice3]: 179 print(i4) 180 choice4 = input("Press b to return to the previous level:") 181 if choice4 == "b": 182 pass 183 elif choice4 == "q": 184 exit () 185 if choice3 == "b": 186 break 187 elif choice3 == "q": 188 exit() 189 if choice2 == "b": 190 break 191 elif choice2 == "q": 192 exit()
标签:菜单 选择 choice ret 返回 ice http data exit
原文地址:http://www.cnblogs.com/the-way-to-bifk/p/7159911.html