11. Making a purchase



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


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.


Thanks for your help! My code works now


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


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!