Purify error


#1

my code is as follows

I don't know what is wrong.


#2

this is these changes to your code.

def purify(number):
i=0
length=len(number)-1
while i <= length:
if number[i]%2 !=0:
del number[i]
length-=1
else:
i+=1
return number

print purify([4,5,5,4])


#3

thank you very much for your reply


#4

can you please explain the purpose of this code ?
length=len(number)-1
while i <= length:


#5

Hi,

this is to simply go through the full string.
length is equal to the length of the string (len(number) ) gives you the length including zero which is why you subtract one.
then to loop through the full string, I initiated i to equal to zero and checked that it is less than the length of the string after we check the value in the string we increase the value of I.