Making a purchase


Hii!! I am getting this error with my code. Please help. (making a purchase)
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 key in prices:
total=total+ prices[key]

    return total

The error is: Oops, try again. compute_bill(['apple']) returned 1.5 instead of 2

Making a Purchase

could you explain me why you loop over prices?

a function ends the moment a return keyword is reached, if the return keyword is reached in a loop, the loop will break to end the function


really sorry.. couldn't follow.. please explain


i asked a question about your loop, can you answer it?


because prices is the dictionary which contains the keys and their prices.


but the purpose of this exercise is to compute a bill of the consumer purchases. Which is stored in food (your function parameter)

so you need to loop over food


It worked!!! thanks a lot!!
Is food a pseudo name for the list here ?