CJCoding With Joseph
15free / daySign inCreate account

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
Topics:
Classes
📥 Auto-Input:
apple\n2\n
This input is automatically fed to your program's stdin
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.