Stocking out


#1



https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/2/3?curriculum_id=4f89dab3d788890003000096


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

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

prices = {
"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 += prices[item]
stock[item] -= 1
return total


Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 4 instead of the correct 7


Replace this line with your code.


#2

Hi @anjusekharan ,

We cannot see the indentation of your code because it is not formatted. However the likely problem is that this statement is indented too much, causing the function to terminate during the first iteration of the for loop ...

return total

It is best to format code when you post it so that we can see all the important details.


#3

Yes it is an indentation error.Now it is fine. Thank you:slight_smile:


#4