← Back to Classes
Question 494
Stock Up The Inventory
Stock Up The Inventory
An Inventory keeps a dict attribute stock that maps an item name to a quantity. Write the body of add: when item is already a key, add quantity to its value; otherwise create the key with quantity as its value. 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 read and pass to add on an inventory that already holds 3 apples; the tests then print each item and its quantity on one line, in alphabetical order.
Expected Output:
apple 5= 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.