Making a purhcase


Oops, try again. compute_bill(['banana', 'apple', 'orange', 'pear']) returned 4 instead of 10.5

I'm not exactly sure what I am missing here but it looks correct. Everything I have tried either returns with "Oops, try again. compute_bill(['banana', 'apple', 'orange', 'pear']) returned 4 instead of 10.5" or "Oops, try again. compute_bill(['banana', 'apple', 'orange', 'pear']) returned 0 instead of 2" and a few indentation errors that I believe I have fixed.

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


Don't know if you still need help, this is over 3 hours old, but it might help you or somebody else in the future.
Your problem is simple,

return total

is just indented one too many times. You don't want it inside of your for loop, because the function will end the first time that the loop, for a lack of better word, loops. (Functions are ended by the return keyword.) Just unindent that line once so that it returns total after all the item prices are added to it.


Yep, that was the issue. Thank you!


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