53.2 Practice: Inventory Management (Python Core) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

29th Jul 2021, 4:51 PM
Cory Peitsch
Cory Peitsch - avatar
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"]
29th Jul 2021, 5:05 PM
Slick
Slick - avatar
+ 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"])
18th May 2022, 2:07 AM
Najwan Najmussabah
0
It's simple the fruit name "Apple" is the key and the value is "8".
29th Jul 2021, 5:19 PM
blackfish
blackfish - avatar
0
Thank you, blackfish and Slick. I had something similar but the code wouldn't work. I probably over complicated it.
29th Jul 2021, 5:25 PM
Cory Peitsch
Cory Peitsch - avatar