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

I do not know what is wrong with my code.


Instead of

you want to compare I to text so it would look like if i == text


thanks to your for loop:

for i in sequence:

i will now hold each item of the list in turn, so then in if statement you could simply see if i equals text

also, a function ends the moment a return keyword is reached, this happens in the first run of your loop, you might want to change the indent of return so the whole loop can run


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