码迷,mamicode.com
首页 > 编程语言 > 详细

Python 基础 - Day 1 Assignment - Three tier menu 三级菜单

时间:2017-07-05 22:53:40      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:bsp   中关村   pen   class   pass   exit   soho   google   sam   

作业要求

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

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

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

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

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

评分标准:

用多层嵌套while循环的方式完成作业2,85分

只用一层循环完成作业2,100分

SAMPLE 1 

技术分享
data = {
    ‘北京‘: {
        ‘海淀‘: {
            ‘五道口‘: {
                ‘soho‘: {},
                ‘网易‘: {},
                ‘Google‘: {},
            },
            ‘中关村‘: {
                ‘爱奇艺‘: {},
                ‘汽车之家‘: {},
                ‘youku‘: {},
            },
            ‘上地‘: {
                ‘baidu‘: {},
            },
        },
        ‘昌平‘: {
            ‘沙河‘: {
                ‘oldboy‘: {},
                ‘北航‘: {},
            },
            ‘天通苑‘: {},
            ‘回龙观‘: {},
        },
        ‘朝阳‘: {},
        ‘东城‘: {},
    },
    ‘上海‘: {
        "黄浦": {
            ‘人民广场‘: {
                ‘炸鸡店‘: {},
            },
        },
        ‘闸北‘: {
            ‘火车站‘: {
                ‘携程‘: {},
            },
        },
        ‘浦东‘: {},
    },
    ‘山东‘: {},
}

exit_flag = False

while not exit_flag:
    for i in data:
        print(i)   # 进入死循环

    choice = input("your option >>>:")
    if choice in data:
        while not exit_flag:
            for j in data[choice]:
                print("\t", j)
            choice2 = input(‘your 2nd option >>>:‘)
            while not exit_flag:
                for k in data[choice][choice2]:
                    print(‘\t\t‘, k)
                choice3 = input(‘your 3rd option >>>:‘)
                if choice3 in data[choice][choice2]:
                    for l in data[choice][choice2][choice3]:
                        print(‘\t\t‘, l)
                    choice4 = input("final, please input b for exit")
                    if choice4 == ‘b‘:
                        pass  # pass == 啥都不做,必须写否则报错。作为占位符
                    elif choice4 == "q":
                        exit_flag = True
                if choice3 == ‘b‘:
                    break
                elif choice3 == "q":
                    exit_flag = True
            if choice2 == ‘b‘:
                break
            elif choice2 == "q":
                exit_flag = True
View Code

 

 

Python 基础 - Day 1 Assignment - Three tier menu 三级菜单

标签:bsp   中关村   pen   class   pass   exit   soho   google   sam   

原文地址:http://www.cnblogs.com/lg100lg100/p/7123717.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!