时间:2020-10-27 12:29:20 | 栏目:Python代码 | 点击:次
本文实例为大家分享了Python三级菜单展示的具体代码,供大家参考,具体内容如下
作业需求:
(1)运行程序输出第一级菜单
(2)选择一级菜单某项,输出二级菜单,同理输出三级菜单
(3)让用户选择是否要退出
(4)有返回上一级菜单的功能
data = { "天津":{ "南开区":{ "南开大学":{ "历史系":{}, "文学系":{}, "英语系":{}, }, "科技大学":{ "计算机系":{}, "机器系":{}, "软件系":{}, }, "理工大学":{ "数学系":{}, "化学系":{}, "物理系":{}, }, }, "武清区":{ "武清大学":{ "历史系":{}, "文学系":{}, "英语系":{}, }, "武清科技大学":{ "计算机系":{}, "机器系":{}, "软件系":{}, }, "武清理工大学":{ "数学系":{}, "化学系":{}, "物理系":{}, }, }, "北辰区":{ "北辰大学":{ "历史系":{}, "文学系":{}, "英语系":{}, }, "北辰科技大学":{ "计算机系":{}, "机器系":{}, "软件系":{}, }, "北辰理工大学":{ "数学系":{}, "化学系":{}, "物理系":{}, }, }, }, "河北":{ "保定市": { "保定大学": { "历史系": {}, "文学系": {}, "英语系": {}, }, "保定科技大学": { "计算机系": {}, "机器系": {}, "软件系": {}, }, "保定理工大学": { "数学系": {}, "化学系": {}, "物理系": {}, }, }, "秦皇岛": { "秦皇岛大学": { "历史系": {}, "文学系": {}, "英语系": {}, }, "秦皇岛科技大学": { "计算机系": {}, "机器系": {}, "软件系": {}, }, "秦皇岛理工大学": { "数学系": {}, "化学系": {}, "物理系": {}, }, }, "石家庄": { "石家庄大学": { "历史系": {}, "文学系": {}, "英语系": {}, }, "石家庄科技大学": { "计算机系": {}, "机器系": {}, "软件系": {}, }, "石家庄理工大学": { "数学系": {}, "化学系": {}, "物理系": {}, }, }, }, "河南":{ "郑州市": { "郑州大学": { "历史系": {}, "文学系": {}, "英语系": {}, }, "郑州科技大学": { "计算机系": {}, "机器系": {}, "软件系": {}, }, "郑州理工大学": { "数学系": {}, "化学系": {}, "物理系": {}, }, }, "南阳市": { "南阳大学": { "历史系": {}, "文学系": {}, "英语系": {}, }, "南阳科技大学": { "计算机系": {}, "机器系": {}, "软件系": {}, }, "南阳理工大学": { "数学系": {}, "化学系": {}, "物理系": {}, }, }, "登封市": { "登封大学": { "历史系": {}, "文学系": {}, "英语系": {}, }, "登封科技大学": { "计算机系": {}, "机器系": {}, "软件系": {}, }, "登封理工大学": { "数学系": {}, "化学系": {}, "物理系": {}, }, }, }, } #exit_flag = False while True: for i in data : print (i) choice = input ("input:") if choice in data: while True: for i2 in data[choice]: print (i2) choice2 = input("input2:") if choice2 in data[choice]: while True: for i3 in data[choice][choice2]: print (i3) choice3 = input("input3:") if choice3 in data[choice][choice2]: for i4 in data[choice][choice2][choice3]: print(i4) choice4 = input("Press b to return to the previous level:") if choice4 == "b": pass elif choice4 == "q": exit () if choice3 == "b": break elif choice3 == "q": exit() if choice2 == "b": break elif choice2 == "q": exit()