[Shopping Trip! - Making a Purchase] I can't find the error: compute_bill(['apple']) returned 10.5 instead of 2


#1

Hi everyone. I'm stuck at the Making a Purchase excercice. Could someone help me to find where the error is, please?

Link to the exercise:
https://www.codecademy.com/en/courses/python-beginner-en-IZ9Ra/2/2?curriculum_id=4f89dab3d788890003000096

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

I thought it was supposed to return 10.5 (the total) in fact, rather than 2? Did I misunderstand the task?

shopping_list = ["banana", "orange", "apple"]

stock = {"banana": 6,"apple": 0,"orange": 32,"pear": 15}
    
prices = {"apple": 2,"banana": 4,"orange": 1.5,"pear": 3}

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

Thank you!


#2

your function parameter (food) contains a list of items you want to buy, so that is what you should loop over


#3

Oh right. Silly mistake, haha. I didn't notice I typed prices instead of food after the in. Thank you very much for the help! It works perfectly now!


#4