Purify


#1



Hello, I'm kinda stuck on this task, and can't figure out what's wrong with my code.


https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/2?curriculum_id=4f89dab3d788890003000096

I tried several approaches, most of the time I get this Message:

Oops, try again.
Your code looks a bit off--it threw a "list index out of range" error. Check the Hint if you need help!


Here is the latest version of my code:


numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

def purify(numbers):
    pure = []
    for num in numbers:
        if num%2!=0:
            return False
        else:
            pure.append(numbers[num])
            
print purify(numbers)

Thanks in advance!

Cheers


#2

things I tried so far:

  1. add a print or return command to my else statement
  2. tried to create a variable for every desired value and later join them to a list

#3

So, I tried to simplify the for loop which I feel is what is messy.

    for num in numbers:
        if num%2 ==0: #this checks if even
            pure.append(num) #appends those num that pass the even test to pure(which is an empty array)
    return pure #returns the for loop which checks for even

So, I really didn't make use of an else condition.

I hope this helps. :wink:


#4

Thanks a million!

It's so simple, it hurts I didn't manage to do it myself :smiley:


#5

You're welcome. Glad I could help! :wink:


#6

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