Compute_bill gives wrong output


My code looks like the following:
def compute_bill(food):
for item in food:
return total

The console returns:
compute_bill([‘apple’]) returned 0 instead of 2

I can’t figure out what I am doing wrong. Does anyone see it?

Why is compute_bill returning the wrong value?

this line:


could you explain what you try to do?


The reason I’m asking here is because I unindented the return total and it didn’t make a difference


did you see my reply:


The instructions said: For each item in the food list, add the price of that item to total .
That’s where my problem most likely is, but it had thrown an error message before that I was trying to combine a string and int, so I was trying to give it an int that it could add to total


what you are currently doing is updating the price of that item to zero (given total is zero)

i know what the instructions are :wink: My answer was intended as hint for you to revise what you attempt here vs what you are actually doing


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