The code works, but there seems to be a bug


#1



purify


Oops, try again. Your function fails on purify([1]). It returns [2, 4, 6, 8] when it should return [


It should work perfectly fine and it does.


clean=[]

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


#2

if we call the function multiply times clean will accumulate data from all the function calls because it isn't defined in the function. This is not desired.


#3

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