Count exercise--are my variables all correct?


#1



I'm not quite understanding the issue in this code. It returns the error message: "Oops, try again. Your function fails on count([4, 'foo', 5, 'foo'],5). It returns 0 when it should return 1."

Any help is appreciated.


This is the exercise for reference:
https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/1?curriculum_id=4f89dab3d788890003000096#


def count(sequence, item):
    found = 0
    for item in sequence:
        if found == item:
            found += sequence[item]
            return count
        else:
            return 0


#2

I don't understand what you're trying to do.

Even if it functioned properly it would return 0 no matter what.


#3

Of course. I see what I did wrong and have managed to fix and pass this.


#5

Here is what I did:

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