15. practice makes perfect


#1


def purify(even):
numbers = []
for number in even:
if not (number in even):
numbers += number
return numbers


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

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


def purify(even):
    numbers = []
    for number in even:
        if not (number in even):
            numbers += number
    return numbers


#3

incorrect, pls help correct it


#4

First of all in python formatting matters so please, indent your code and to make it better readable wrap it in such an environment:

```python
your code
```

next up add a link to the exercise or at least explain what your input is. According to this line:

for number in even:

it is not a single number.

Also if numbers is a list then numbers += number might not work. So please give some more information.


#6

I have corrected it. Done @haxor789


#7

Ok the first thing is that you should think of a better idea on how to find even numbers, because this doesn't work:

    for number in even:
        if not (number in even):

Because what it means is:
Do this for every element of even: Take a number from the list named even and check if this number is not in the list even. It obviously is in the even list because you took it from that list the very line before :slight_smile:
Therefore you'll always end up with an empty list.

And the other thing is that when you want to add a new element to a list you're better off using LISTNAME.append(number) instead of numbers+=number


#8

like this:

     def purify(even):
        new = []
        for i in even:
            if i%2==0:
                new.append(i)
        return new

#9

Yes, that should be much better.


#10

thanks @haxor789 .:wink:


#11

can you also help with this:
https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/2/3?curriculum_id=4f89dab3d788890003000096

def product(integers):
for i in integers:
if i*i:
integers.append(i)
return integers
print integers

error message:
Oops, try again. Your function does not return an int.

that is for the next lesson on product, i am trying to multiply the numbers in : if i*i, but i know its not correct.


#12

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