Count problem


Count exercise

Oops, try again. Your function fails on count([4, 'foo', 5, 'foo'],5). It returns 0 when it should return 1.

Thought it would check if they're equal and then add 1 to the count

def count(sequence, item):
    c = 0
    for a in sequence:
        if a == item:
            c = c +1
        return c


Be sure your return is not inside the loop.


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