Objective
Create a Python program that controls a shop inventory with its own class and a custom exception for insufficient stock.
Instructions
- Read an integer
nand thenncommands, one per line. Names have no spaces and quantities are positive integers. add NAME QUANTITY: adds units and showsAdded: NAME (+QUANTITY).remove NAME QUANTITY: subtracts units and showsRemoved: NAME (-QUANTITY). If the product does not exist, showError: unknown product NAME. If there are fewer units than requested, showError: insufficient stock of NAME (there are H, requested Q)and change nothing.check NAME: showsNAME: units, or the unknown product error.report: oneNAME: unitsline per product, sorted from most to fewest units (tie: by name), orEmpty inventoryif there are no products; thenTotal units: T.
6
add tornillo 50
add clavo 20
remove tornillo 15
check tornillo
remove clavo 30
report
Added: tornillo (+50)
Added: clavo (+20)
Removed: tornillo (-15)
tornillo: 35
Error: insufficient stock of clavo (there are 20, requested 30)
tornillo: 35
clavo: 20
Total units: 55
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise