Purify


#1

count=[]
c1=[]
def purify(x):
    for i in x:
        if i%2==0:
            count.append(i)
            print ('these are the even numbers:')
            print count
        return count
        
purify([1,2,3,4])

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


#2

everything you need to purify the list should be inside the function, because count=[] is not inside the function, count will accumulate when the function is called multipy times

also, a function ends the moment a return keyword is reached

so currently, your function ends in the first itertion/run of your loop


#3

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