CJCoding With Joseph
15free / daySign inCreate account

Stock Report

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; total_items() loops over the keys and returns the sum of every quantity; report() prints one line per item as <item>: <quantity> in alphabetical order, looping over sorted(self.stock). 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 add on an inventory already holding 3 apples and 5 pears; the tests then call report and print the total.

Expected Output:

apple: 5
pear: 5
10

= newline. The output ends with a newline — print one after the last line.

Hints4 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.