Listng your problems : Count



I have stucked at this exercise. Cant understand why it returns an error.


I got an error message :
Your function fails on count([1],7). It returns 1 when it should return 0

def count(squence, item):
    found = 0
    for item in squence :
        if item in squence:
            found = found + 1
        return found


your for loop:

for item in squence :

item will now hold items of the squence. instead of the second function parameter. Then of course item will be in sequence, since item holds the items in the sequence. Loop over the items in squence, but don't call it item, call it x or whatever you like:

for x in squence:

also, the compare if x is equal to (==) to item

Also, change the indent of the return keyword, a function ends the moment a return keyword is reached, which in your code happens in the first run of the loop


Thanks a lot. Problem solved