12. purify


#1


  1. purify

Code works but codecademy does not accept it. Gives error that it fails when it really passes.

I expect it to accept the code...


numbers = []
numbers2 = []

def purify(numbers):
    i = 0
    while i < len(numbers):
        if numbers[i] % 2 == 0:
            numbers2.append(numbers[i])
        i += 1
    print numbers2
    return numbers2


purify([1,2,4,16,17,20])


#2

Those are both in global scope. Recommend remove both and define just one list inside the function. The parameter is the other one.

Unless this is for debugging purposes it may be removed as it is not asked for in the instructions.


#3

Thanks for the suggestion.

Right, the print numbers2 was for debugging purposes.

If this worked for you as well I think I should have reported a bug instead of posting to this forum....


#4

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