Count the Stock

Python for AIMedium+10 XP+10

Count the Stock

Each shop saves its stock as a JSON file shaped like this:

json
1{"shop": "Corner", "items": [{"name": "pens", "qty": 4}, {"name": "pads", "qty": 9}]}

Write total_stock(path) that opens the JSON file at path and returns the total of every item's "qty". A shop with no items has a total of 0.

The starter code creates five files for you (shop_a.json to shop_e.json). Keep those lines.

Examples

path = "shop_a.json"
returns 13
path = "shop_b.json"
returns 12

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