Fix the Price, Then Report

Data with PythonHard+10 XP+10

Fix the Price, Then Report

A bakery's order sheet has one wrong price: every order of one item was charged at an old price. Before the weekly report, the price has to be put right in the table, and then the report is worked out from the corrected table.

Task: write weekly_report(orders, item, new_price, big).

  • orders is a list of dictionaries, each with order_id, item, price and qty. Every price is a decimal number, like 3.0 or 2.4.
  • Change the price of every order of item to new_price. Item names must match exactly. If item never appears, nothing changes.
  • Then add a total column: price × qty.

Return a list of three things:

  1. the sum of all totals, rounded to 2 decimal places
  2. the order_id of the order with the largest total
  3. how many orders have a total of at least big

There is always at least one order, and no two orders share the largest total.

Examples

orders = [{"order_id": "B1", "item": "loaf", "price": 2.4, "qty": 5}, {"order_id": "B2", "item": "scone", "price": 1.5, "qty": 12}, {"order_id": "B3", "item": "loaf", "price": 2.4, "qty": 10}, {"order_id": "B4", "item": "cake", "price": 14.0, "qty": 1}]
item = "loaf"
new_price = 2.8
big = 15
returns [74.0, 'B3', 2]
orders = [{"order_id": "C1", "item": "bun", "price": 0.9, "qty": 20}, {"order_id": "C2", "item": "tart", "price": 3.2, "qty": 4}]
item = "pie"
new_price = 4.0
big = 13
returns [30.8, 'C1', 1]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run