← Back to Classes
Question 495
How Many In Stock
How Many In Stock
An Inventory keeps a dict attribute stock from item name to quantity, and add is already written. Write the body of quantity so it returns the stored amount for item, or 0 when the item is not a key at all; reading a missing key directly would crash. Do NOT write a main block or any top-level test code; the tests construct the class. Input: one line, an item name, which the tests read and pass to quantity on an inventory holding 3 apples and 5 pears before printing the number your method returns.
Expected Output:
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.