Error on "Making a purchase"


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

I do not know why this is not working. I have followed the example as best as I can, but what I'm taking from this is that += is incorrect somehow? Could someone explain this?

shopping_list = ["banana", "orange", "apple"]

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3

# Write your code below!
def compute_bill(food):
    total = 0
    for item in food:
        total += item
    return total
n = [1, 2, 5, 10, 13]
print compute_bill(n)


when you call the function:

print compute_bill(n)

why supply n argument? You should supply a list with products (for example shopping_list) as argument. This would also explain the error. total is integer, and item is a string, how would you get from product to price?


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