The Patchy Stock Sheet

Data with PythonMedium+10 XP+10

The Patchy Stock Sheet

A gift shop's stock sheet is a list of dictionaries with the keys "item", "price" and "qty". Some boxes are None.

The owner decides how to treat each kind of gap:

  • Missing price: the item can't be valued, so drop that row.
  • Missing quantity: a blank means none were counted, so fill it with 0.

Write stock_value(items). After handling the gaps, return the total value of the stock: the sum of price × qty over the rows that are left, rounded to 2 decimal places. If every row is dropped, return 0.0.

items always has at least one row.

Examples

items = [{"item": "mug", "price": 6.5, "qty": 4}, {"item": "card", "price": 2.25, "qty": None}, {"item": "candle", "price": None, "qty": 10}, {"item": "soap", "price": 3.8, "qty": 5}]
returns 45.0
items = [{"item": "pen", "price": 1.2, "qty": 10}, {"item": "pad", "price": 2.0, "qty": 3}]
returns 18.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