Python学习第一天-编写三级菜单

编写三级菜单:

1. 运行程序输出第一级菜单

2. 选择一级菜单某项,输出二级菜单,同理输出三级菜单

3. 菜单数据保存在文件中

4. 让用户选择是否要退出

5. 有返回上一级菜单的功能

# Author: zfh

data = {
    "陕西":{
        "汉中":["张骞故里","古汉台"],
        "西安":[],
        "商洛":[]
    },
    "山西":{
        "太远":[],
        "运城":[],
        "平凉":[]
    },
    "山东":{
        "青岛":[],
        "济南":[],
        "聊城":[]
    }
}
exit_flag = False
while not exit_flag:
    for i in data:
        print(i)
    choice = input("请输入选择1>>:")
    if choice in data:
        while not exit_flag:
            for i1 in data[choice]:
                print("\t",i1)
            choice1 = input("请输入选择2>>:")
            if choice1 in data[choice]:
                    for i2 in data[choice][choice1]:
                        print("\t\t",i2)
                    choice2 = input("最后一层,按b返回>>:")
                    if choice2 == "b":
                        pass
                    elif choice2 == "q":
                        exit_flag = True
            if choice1 == "b":
                break
            elif choice1 == "q":
                exit_flag = True
    if choice == "b":
        break
    elif choice =="q":
        exit_flag = True
View Code

猜你喜欢

转载自www.cnblogs.com/fameg/p/9652183.html