12. Stocking Out - Fail, assistance please


#1

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(shopping_list):
total = 0
for food in shopping_list:
if stock[food] > 0:
total += prices[food]
return total

compute_bill(shopping_list)

Where is my code not functioning?


#2

return total is inside your for loop, but needs to run after it instead. So remove 4 spaces infront of it.

Also don't forget step 2 of the instructions.


#3

Thank you so much, that worked.