Stock tracker with low-stock alerts
Mediumclassdictionary attributeraisesorted· 20 XP
A small shop wants to track stock and get a list of items that are running low.
Write a class Stock with:
receive(item, qty)that adds units of an itemsell(item, qty)that removes units, raisingValueError("not enough stock")if there aren't enough (an unknown item has 0)low(threshold)that returns an alphabetically sorted list of items with fewer thanthresholdunits, including items that have dropped to 0
How it's checked
Your code runs, then the check below runs and its printed output is compared with ours.
- After receiving 5 mugs and selling 4,
low(2)returns["mug"]
Hints, the later questions and the answer come with Pro.
class Stock:
def __init__(self):
...