Count error



I get an error message saying that it takes too long for my code to return a result and to check for an infinite loop. When I run this outside of the codecademy site it works fine. What am I doing wrong?

Should return a count of the specified integer (item) found within a given list (sequence).

def count(sequence,item):
    i = 0
    found = 0
    while i <= len(sequence):
        if item in sequence:
            found += 1
            i += 1
    return found


Make a change to the code.....



while i < len(sequence):


Thanks, but I still get the same error with that change.


Use the following code

sequence = [0,1,2]
print len(sequence)
print len(sequence)

and you will know
that removei-ing an item from the squence
will change its len-ght


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