11. Count


11. Count

So this code actually prints 3, which is should, but the program is still giving me this error:

Oops, try again. Does your count function take exactly two arguments: a list and an item to check against that list? Your code threw a "unsupported operand type(s) for +=: 'int' and 'str'" error.

Is this a Codecademy program issue or is my code actually off?

def count(sequence, item):
    found = 0
    for i in sequence:
        if i == item:
            found += i
    return found
print count([1,2,1,1],1)


this line:

found += i

why did you add i? if the item is found, you should just add 1 (because the item is found), item might not always be one, it can also be a string (wich explains the error)


That worked! Your explanation makes sense. Thank you!