三级菜单程序

三级菜单程序:
一、 程序要求:
1、 编写三级菜单,可选择进入子菜单
2、 任意一级菜单内都可以返回任意上一级菜单
3、 任意一级菜单内都可以推出程序

二、 程序流程图

在这里插入图片描述
三、 Readme
1、 输出一级菜单,用户输入子菜单编号即可进入相应二级菜单,二级、三级菜单同前,任意一级菜单都可返回上一级菜单,并能随时推出

四、 程序代码及注释

city = {5:"(5)quit",3:"(3)up     ",4:"(4)back     ",1:"(1)BZ     ",2:"(2)WLMQ     ",11:"(11)hj     ",111:"8_trees     ",112:"hegang     ",12:"(12)yanqi     ",121:"beidaqu     ",122:"wuhaoqu     ",21:"(21)changji     ",211:"chang1     ",212:"chang2     ",22:"(22)kuitun     ",221:"kui1     ",222:"kui2     "}   #定义三级菜单的字典
level1 = 1   #level1-3三个变量分别为不同值时,各级菜单的循环执行与否也不同
level2 = 1
level3 = 1

while level1 == 1:
    print(city[1],city[2],city[5])   #输出一级菜单
    choose1 = input("choose:")   #一级菜单的用户输出变量
    level2 = 1   #循环从其它层级跳回一级菜单后,将level2-3赋值1,以便程序重新执行
    level3 = 1   #循环从其它层级跳回一级菜单后,将level2-3赋值1,以便程序重新执行
    while level2 == 1:
        if choose1 == "1": 
            print(city[11],city[12],city[3],city[5])   #输出二级菜单
            choose2 = input("choose")   #二级菜单的用户输出变量
            while level3 == 1:
                if choose2 == "11":
                    print(city[111],city[112],city[3],city[4],city[5])   #输出三级菜单
                    choose3 = input("choose")   #三级菜单的用户输出变量
                    if choose3 == "3":   #返回上级菜单
                        break
                    elif choose3 == "4":   #返回一级菜单
                        level2 = 2
                        break
                    elif choose3 == "5":
                        print("bye!")
                        level2 = 2
                        level1 = 2
                        break
                elif choose2 == "12":
                    print(city[121],city[122],city[3],city[4],city[5])   #输出三级菜单
                    choose3 = input("choose")   #三级菜单的用户输出变量
                    if choose3 == "3":   #返回上级菜单
                        break
                    elif choose3 == "4":   #返回一级菜单
                        level2 = 2
                        break
                    elif choose3 == "5":   #退出所有程序
                        print("bye!")
                        level2 = 2
                        level1 = 2
                        break
                elif choose2 == "3":   #返回上级菜单
                    level2 = 2
                    break
                elif choose2 == "5":   #退出所有程序
                    print("bye!")
                    level2 = 2
                    level1 = 2
                    break
                else:
                    break
        elif choose1 == "2":
            print(city[21],city[22],city[3],city[5])   #输出二级菜单
            choose2 = input("choose")   #二级菜单的用户输出变量
            while level3 == 1:
                if choose2 == "21":
                    print(city[211],city[212],city[3],city[4],city[5])   #输出三级菜单
                    choose3 = input("choose")   #三级菜单的用户输出变量
                    if choose3 == "3":   #返回上级菜单
                        break
                    elif choose3 == "4":   #返回一级菜单
                        level2 = 2
                        break
                    elif choose3 == "5":   #退出所有程序
                        print("bye!")
                        level2 = 2
                        level1 = 2
                        break
                elif choose2 == "22":
                    print(city[221],city[222],city[3],city[4],city[5])   #输出三级菜单
                    choose3 = input("choose")   #三级菜单的用户输出变量
                    if choose3 == "3":   #返回上级菜单
                        break
                    elif choose3 == "4":   #返回一级菜单
                        level2 = 2
                        break
                    elif choose3 == "5":   #退出所有程序
                        print("bye!")
                        level2 = 2
                        level1 = 2
                        break
                elif choose2 == "3":   #返回上级菜单
                    level2 = 2
                    break
                elif choose2 == "5":   #退出所有程序
                    print("bye!")
                    level2 = 2
                    level1 = 2
                    break
                else:
                    break
        elif choose1 == "5":   #退出所有程序
            print("bye!")
            level1 = 2
            break
        else:
            break

猜你喜欢

转载自blog.csdn.net/weixin_41772367/article/details/89075548
今日推荐