Stuck even though I followed instructions exactly


TypeError: cannot concatenate 'str' and 'list' objects

It should have returned the total of all foods.

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


This is in spite of me following all directions and even me checking the next part to see if I was correct (I was)


total is already defined as the accumulator. Use a different variable in the loop.

    for item in food:
        total = total + food[item]

May also be written,

total += food[item]

They main thing is to accumulate the value for each item.


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