找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 5067|回复: 4

[求助] 学校作业,大神动一动小手帮忙看看呗,第一次学编程软件

1

主题

1

帖子

1

积分

贫民

积分
1
Oliver\Tang 发表于 2019-8-15 11:43:01 | 显示全部楼层 |阅读模式
1威望
For all discontinued products (i.e. discontinued = 1):
  • Print the product_id on one line
  • On another line print their product_category together with their product_description formatted as "product_category - product_description"
  • A blank line should be printed between successive products
Notes:
  • You MUST use a loop and a conditional statement.
  • Hardcoding the answer (i.e. manually computing the answers) will result in no mark for this question. The answer must be "programmed" using a loop and a conditional statement.







products = [
    {
        "discontinued": 0,
        "lead_time_days": 4,
        "product_category": "Toy",
        "product_description": "Pull out a bock without crashing the stack ...",
        "product_id": 101,
        "product_name": "Jenga Classic Game",
        "reorder_level": 50,
        "unit_price": 14.99
    },
    {
        "discontinued": 0,
        "lead_time_days": 4,
        "product_category": "Wireless Phone Accessory",
        "product_description": "Display: 2.5 inches Camera: 2 MP Talk Time: 4.5 hours Weight: 3.3 ounces",
        "product_id": 102,
        "product_name": "AT&T Z431 GoPhone (AT&T)",
        "reorder_level": 14,
        "unit_price": 49.99
    },
    {
        "discontinued": 1,
        "lead_time_days": 4,
        "product_category": "Wireless Phone Accessory",
        "product_description": "Display: 4.5-inches Camera: 5-MP Input: Touchscreen OS: Android",
        "product_id": 103,
        "product_name": "AT&T Z998 LTE Android Go Phone (AT&T Prepaid)",
        "reorder_level": 29,
        "unit_price": 159.99
    },
    {
        "discontinued": 1,
        "lead_time_days": 4,
        "product_category": "Personal Computers",
        "product_description": "8 inch Display (1920x1200) ...",
        "product_id": 104,
        "product_name": "NVIDIA SHIELD Tablet (WiFi)",
        "reorder_level": 10,
        "unit_price": 299.0
    }
]

回复

使用道具 举报

0

主题

18

帖子

18

积分

贫民

积分
18
wengboyu 发表于 2019-8-15 16:04:04 | 显示全部楼层
  1. def print_product():
  2.     for product in products:
  3.         print(product['product_id'])
  4.         print('{} - {}'.format(product['product_category'], product['product_description']))
  5.         print()
复制代码
回复

使用道具 举报

0

主题

18

帖子

18

积分

贫民

积分
18
wengboyu 发表于 2019-8-15 16:07:26 | 显示全部楼层
题目说要一个条件语句 问题是这个不需要条件语句 我不知道这个题目到底想干嘛
回复

使用道具 举报

0

主题

8

帖子

8

积分

贫民

积分
8
Dr.MarTin 发表于 2019-8-16 15:28:19 | 显示全部楼层
考虑异常条件, 譬如某个条目要打印的数据缺失。
回复

使用道具 举报

0

主题

6

帖子

6

积分

贫民

积分
6
阿姨不想洗铁路 发表于 2019-8-26 16:32:25 | 显示全部楼层
for product in products:
    if product['discontinued'] == 1:
        print(product['product_id'])
        print('{} - {}'.format(product['product_category'], product['product_description']))
        print()
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表