11. Making a purchase


#1



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


Hi, can someone please explain why this code isn't working.
This is the error message I get: "Oops, try again. compute_bill(['apple']) returned 4 instead of 2"

I have no idea where that 4 is coming from...
Any help or explanation would be greatly appreciated!


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

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}
    
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}

def compute_bill(food):
    total= 0
    for food in shopping_list:
       total += prices[food]
       return total


#2

food is a list which is being passed to the compute_bill function. In your for loop, you should be going through the items in food.


#3

Thanks for your help! My code works now


#4

how did you fix the code can you tell me exactly what you did


#5

def compute_bill(food):
total= 0
for items in food:
total += prices[items]
return total

food is a list and items describes what is in the list food, as joshuaitz said. Hope this helps!