Purify help?


A little stuck, this is what I've got so far:


so I've been working on this while I wait for a response:

now I'm getting the error:
Oops, try again. Your code looks a bit off--it threw a "purify() takes exactly 1 argument (4 given)" error. Check the Hint if you need help!


resolved the previous error but now have a new one:

Oops, try again. Your function crashed on [1] as input because your function throws a "'NoneType' object is not iterable" error.


Your function should accept a list of numbers and return a list of numbers. In each case here, you've either accepted or returned some other type


how do I specify that the input will be a list?


You don't, you simply treat it as such. You were giving it four arguments at some point.
You'd specify input/output as documentation, that's where promises about behaviour goes. (aside from the source itself)


I'm confused, sorry.

Are you saying that I set up the code correctly but did something wrong with the print statement?
Sorry I'm very new to this and don't know much of the lingo yet.


Oops, try again. Your function crashed on [1] as input because your function throws a "'NoneType' object is not iterable" error.

I'm getting this error for the following implying there's something wrong with how I defined the input I assume:


I'm not sure but personally I'd define is_even thing before the for loop.

Also why would you print n instead of adding n to the is_even list? Are you sure that the print function works as intended?


I tried putting is_even before the loop but it doesn't make a difference.. I also already tried adding n to is_even earlier on but it gave me another error..
I actually don't know what I'm doing at this point but thanks for trying to help :slight_smile:


Your last function doesn't return a list, it returns the result of appending, which is None, there is no result of that action, instead it has a side-effect which is that something gets appended to is_even.

Like @karaeska points out, you shouldn't set your results list to an empty list on each iteration, because then you're throwing away everything you did before each time you process next number


Ok I'm going to try fix it, give me a bit


Yeah I think I just don't know enough to be able to solve this.
I don't understand when exactly am I supposed to tell it to append the is_even list and whether or not I need a separate print n statement in the first loop

Could you maybe give me the answer so I can see what it is I was supposed to do?


Alright, so the program shows you two errors.

The one on line 10 (printing purify thing) – why would you print a function with given arguments, if you have already given it an argument (numbers)? Simple print purify should suffice.

About the second error, I gotta think about that (maybe someone meanwhile will post the answer), so stay tuned.


Okay, actually I looked at my post before and I thought: wait, why are you returning purify?

Purify is the name of the function, in which you have to return (not print, by the way; exercise wants you to return it) the result of the function. So here the result would be the list without the odd numbers, so you'd want to return this list.

I have no idea though what happens with the TypeError. If I have an idea, I'll let you know. Or maybe someone else will post. I cannot help much since I went the other way in this exercise (I removed the odd numbers from the list instead of appending prime numbers to the new list), but I'll be thinking hard! :slight_smile:

EDIT: A little thing: list.append(n), not [n]!!!


Okay, sorry for the third post in the row (I hope this will be the last one), but I figured it out.

First of all, as I mentioned in edit to the post before, list.append(n), not [n]. That would be the error number one.

Second thing is that I removed else statement (it is not useful here really), I removed n +=1 thing (why would you add anything to any number in the first version of the list?), I also made the function return the result of the new list.

And… it works. I won't copy/paste the code, but things from there should be pretty simple :wink:


This is it..
I was waaay off.. but I get it now.

Thank you SO MUCH for your help!


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