0

Again with a new question :D

Heeey . can somone help me with this question : Dictionaries Dictionaries can be used to store key:value pairs. 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.

8th Oct 2021, 5:39 PM
Raoof Zakarna
4 Réponses
+ 1
Use `get()` method to obtain an item value, given a key. See the third slide in this https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2451/
8th Oct 2021, 8:04 PM
Ipang
+ 1
# Fore any type of fruit in inventory :) # Takes fruit as input and returns how many there are in the store. store = {"Orange": 2, "Watermelon": 0, "Apple": 8, "Banana": 42} user_input = input("Enter type of fruit: ").capitalize() if user_input in store: print("There are", store[user_input], "of them.") else: print("This fruit has not been catalogued.")
2nd Mar 2022, 10:30 AM
Matumbai Binale
Matumbai Binale - avatar
0
not working but i fix it
8th Oct 2021, 8:49 PM
Raoof Zakarna
0
print(store['Apple']) or print(store.get('Apple'))
8th Oct 2021, 8:53 PM
ubai
ubai - avatar