could anyone tell me what is wrong with my code?

Oops, try again. Your function fails on count([4, 'foo', 5, 'foo'],5). It returns 0 when it should return 1.

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

print count([1,2,"dust",3,3,3], 3)


your code is fine. Seems you hit a glitch. Try refreshing the page/different browser


Seconded. Your code is fine, seems to be a glitch in the matrix. Try a different browser. YOu can verify your code by running it in terminal, but I've also tried yoru code and it works just fine.


well actually the code works fine, but there is a symantic error:

print count([1,2,"dust",3,3,3], 3)


print count([1,2,"dust",3,3,3], "3")

have same results, but they shouldnt.
the second one should result 0 but it results 3 because of str-conversion


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