11. count


11. count / 15) practice makes perfect at 66% of python course

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

def count(sequence, item):

    found= 0
    for i in sequence:
        if i == item:
           found += 1
           return found 
            return found


a function ends the moment a return keyword is reached, so you want to return found after the for loop


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