12/13 May I know why my code isn't working? Thank you in advance


#1

shopping_list = ["banana", "orange", "apple"]

stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}

price = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}

Write your code below!

def compute_bill(food):
total = 0
for item in food:
if stock(item)>0:
total+=price[item]
stock[item]-=1
return total

It reutrns :"calling compute_bill with a list containing 1 apple, 1 pear and 1 banana caused the following error: 'dict' object is not callable"


#2

the problem is on this line

if stock(item)>0:

you are trying to check if the the item in the dictionary is still in stock but the way you wrote it implies you are calling a function which is not the case thats why you get the error. To correct it you need to do

if stock[item]>0: