Count - executes code differently when validating


#1




https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/1?curriculum_id=4f89dab3d788890003000096#

In what way does your code behave incorrectly? Include ALL error messages.

Code executes perfectly in editor, however it does not provide the same result when executed in the validation. I get the error:

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

While when I write print count([4, 'foo', 'foo'],5) after my function it returns the correct value.

What do you expect to happen instead?

I expect the code to run in the validation with no mistakes in output.


def count(sequence,item):
    c=0
    while item in sequence:
        del sequence[sequence.index(item)]
        c+=1
    return c


#2

you modify the list, this seems to give problems with the validation


#4

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