Purify


#1

I don't understand what is wrong with my code.... It says:

Your code threw a "unsupported operand type(s) for %: 'list' and 'int'" error.

def purify(x):
....new_lst = []
....for num in x:
.........if x % 2 == 0:
............new_lst.append(num)
....return new_lst


#2

Found out my problem... if anyone cares its that i do:

x % 2

instead of

num % 2


#3

Hello, you will have to change x to num so you have if num%2==0 instead of if x%2==0 :smiley:


#4

def purify(x):
for i in range(0,len(x)):
if (x[i])%2 == 1:
x.remove(x[i])
return x
@gigaace55222 can you please tell me why I'm getting "list index out of range" error


#5

As soon as you remove 1 element the list becomes smaller in your for loop, causing an out of range error when indexing.