End-of-Day Order Report

Python for AIHard+10 XP+10

End-of-Day Order Report

At closing time, a shop goes through all of today's orders at once. Each order is a tuple (item, quantity), where the quantity is text.

Write day_report(prices, orders) that returns a dictionary with three keys:

  • "total": the sum of prices[item] * int(quantity) for every order that works
  • "unknown": how many orders asked for an item not in prices
  • "bad_quantity": how many orders had a quantity int() can't read

If an order has both problems, count it as "unknown" only.

Examples

prices = {"apple": 40, "bread": 120}
orders = [("apple", "3"), ("cake", "1"), ("bread", "a few"), ("bread", "2")]
returns {'total': 360, 'unknown': 1, 'bad_quantity': 1}
prices = {"apple": 40}
orders = []
returns {'total': 0, 'unknown': 0, 'bad_quantity': 0}

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