← Back to Classes
Question 506
Remove From Stock
Remove From Stock
Write the whole Inventory class. The constructor creates an empty dict attribute stock from item name to quantity; add(item, quantity) tops up an existing key or creates it; remove(item, quantity) subtracts from the stored quantity, but when the item is missing or holds fewer than requested it prints Not enough <item> and changes nothing. Do NOT write a main block or any top-level test code; the tests construct the class. Input: two lines, an item name and a whole-number quantity, which the tests pass to remove on an inventory holding 5 apples; the tests then print each item and its quantity on one line, in alphabetical order.
Expected Output:
apple 3= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Classes
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.