Making a Purchase: Wrong Output


#1

I followed all the directions, but the error message says:
Oops, try again. compute_bill(['banana', 'apple', 'orange', 'pear']) returned 4 instead of 10.5
Here is my code:

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

Thanks,

Coder_Emma


#2

total should be initialized before the loop. Be sure the return statement is not inside the loop.

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