+ 1
53.2 Practice: Inventory Management (Python Core)
Dictionaries Dictionaries can be used to store key:value pairs. I'm at a loss on how to go about this, I've reviewed the lesson a couple of times and I don't know what to do. The problem: You have been asked to create an inventory management program for a store. You use a dictionary to track all of the store's inventory along with how many of each item the store has. store = {"Orange": 2, "Watermelon": 0, "Apple": 8, "Banana": 42} PY Complete the provided code to output the number of apples present in the store. Dictionaries can be indexed just like lists, using square brackets. Starting code: store = {"Orange": 2, "Watermelon": 0, "Apple": 8, "Banana": 42} #your code goes here
4 Answers
+ 3
instead of a numbered index like lists (usually) you use the "key" as the index.
To print the 8 that's after Apple, you'd print store["Apple"]
+ 2
store = {"Orange": 2, "Watermelon": 0, "Apple": 8, "Banana": 42}
#your code goes here
# print the 8 that's after Apple, you'd print store["Apple"]
print(store["Apple"])
0
It's simple the fruit name "Apple" is the key and the value is "8".
0
Thank you, blackfish and Slick. I had something similar but the code wouldn't work. I probably over complicated it.