Help with "Count" stage



it prints 0 but it is saying it returns 1

it is returning 0 that is why i am able to print it, why am i not able to complete the task then

def count(sequence,item):
    lenth1 = len(sequence)
    found = 0
    for a in range (lenth1):
        if item in sequence:
            found = found + 1
            print sequence
    return int(found)

print count([4,'foo','foo'],5)


Is that called for, or just debugging code?


Again, ... ???

Consider, our loop takes an item from the sequence and compares it to the test value. If a match is found, the accumulator is incremented. No change in the data sequence takes place. Next item.


debug code.

i wanted to check every single letter for the item.

then removed the found item so it does not run with the loop again.

as i said again, the answer returns 0, but the codecademy pop up says it returns 1.


We're really only meant to count the matched items in the sequence, nothing more. We're iterating the sequence, so no items once viewed are repeated.


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