Making a Purchase (Correct code (?), wrong total)


#1

Hi, I've checked other posts regarding this topic, in particular the code. My code isn't wrong I think, but I can't get the correct total for prices. Here's 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):
total = 0
for key in shopping_list:
total += prices[key]
return total

I get this error message:
Oops, try again. compute_bill(['apple']) returned 7.5 instead of 2

Any help and clarification is much appreciated!


#2

Okay, I've managed to solve this section by changing the code to the following:

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

The difference is food vs shopping_list in the loop function. Can somebody explain what's the difference? Thanks.