Loading...
Loading...
A shop has this stock: pen 10, book 5, bag 2. The first input line is the number m of orders. The next m lines are item quantity.
Define your own error class OutOfStockError. For each order: if the item is not in the stock print Unknown item: <item>. If the quantity is not a whole number above 0 print Invalid quantity. If the quantity is more than the stock raise OutOfStockError and print Out of stock: <item>. Otherwise reduce the stock and print Shipped <quantity> <item>.
item quantity.Example
Input
4 pen 3 bag 5 box 1 book x
Output
Shipped 3 pen Out of stock: bag Unknown item: box Invalid quantity
Shipped, out of stock, unknown item, invalid quantity.
Try the problem first. Open one hint at a time.
Create the class with class OutOfStockError(Exception): pass. Look up the stock with [] to get KeyError for unknown items.
Check the quantity text before looking at the stock. Raise OutOfStockError when it is too large and catch it by name.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor