Compute_bill gives wrong output


#1

My code looks like the following:
def compute_bill(food):
total=0
for item in food:
prices[item]+=total
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?
#2

this line:

prices[item]+=total

could you explain what you try to do?


#3

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


#4

did you see my reply:


#5

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


#6

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


#7

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