Error message says apple's price is 6 instead of 2


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

this is my code, but it doesnt seem to work
the error msg shows "Oops, try again. compute_bill(['apple']) returned 6 instead of 2"


It looks like your code didn't print the correct total
#2

The variable shopping_list is not parameter of your function compute_bill. Try to use food in you for loop.

Also use key instead of "food" like this:

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

#3

thanks alot !!!! i works now