11. making a purchase


#1

Even i'm facing the same issue. My code looked like this:

Write your code below!

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

And this returned error "Oops, try again. compute_bill(['apple']) resulted in a TypeError: unsupported operand type(s) for +=: 'int' and 'str'"

This is because i thought he argument 'food' is a list. But it turned out to be a dictionary.
So, modifying the last second line to "total += prices[item]" solved my issue.

My question is: where did we mention that 'food' is a dictionary and not a list????


11 Making a Purchase
#2

Should be

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


#3

@ravanamsuresh I face the same problem


#4

@rubycoder87603 it worked, thanks! :smile:


#5

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