Making a purchase lesson help


#1



https://codecademy.com/courses/python-beginner-en-IZ9Ra/2/2?curriculum_id=4f89dab3d788890003000096


the error is "compute_bill(['banana', 'apple', 'orange', 'pear']) returned 4 instead of 10.5" and I cant figure out the mistake I made.


prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5, 
    "pear": 3
}

# Write your code below!
def compute_bill(food):
    total = 0
    for foods in food:
        total += prices[foods]
        print total
        return total


#2

What operations would it need to have done to reach 10.5? How can you find out if it did those? Can you make it tell you what it does as it runs? And if so, where did it go wrong?


#3

Add all of the prices when you insert all four types, but it always comes out with four. I think it is just running it through for banana, but I can't see why.


#4

this had the answer: apparently the return cant be indented inside the for loop or else it terminates the function. https://discuss.codecademy.com/t/11-making-a-purchase-total-has-wrong-value/50315


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.