"'NoneType' object is not iterable"


#1



purify


"'NoneType' object is not iterable"


this is my code:
def purify(num):
    for n in num:
        if (n%2)!=0:
            num=num.remove(n)
    return num


#2

Have you read the error message?
What do you think it's saying?
Based on what it's saying, where in the code is it probably happening?
What can you do to investigate that?
Is there some particular information you need to address that problem?


#3

yeah the error is nonetype object is not iterable which i belive means theres no input but how can i fix it


#4

You're not calling your function at all, so nothing happens while only your code runs - including any errors (aside from syntax problems)

At second glance, that exception is actually raised outside your code, but the problem is with your code.

Test your code - call it with some input and look at what it returns.

When you find some output that your function isn't behaving correctly for, comment out the other test input and start inserting prints in your function to investigate what it was doing step by step. You can for example print out what the current value is, and what num is after each time you update it - that would give a good overview of how it's running, right?


#5

i tested it it still gives the same error


#6

Making your own tests doesn't and shouldn't affect the submission test, that's not the outcome to look for.

Instead, call the function and look at what it returned. Compare what your function returns to what your function is supposed to return

result = purify([1, 2, 3, 4])  # should return [2, 4] .. or [1, 3] whichever it is
print 'return value: {!r}'.format(result)

#7

in the screen that shows the result it shows none i cant figure out where is the mistake i tried using an if and elif and it didint work i think everything is alright i just do not know what to change anymore


#8

If it returns None and it should have returned a list, then you must surely have lost track of that list somewhere, yeah?

You can now use print statements to follow along in what you do with the list, at some point it'll go from being a list to having been replaced by None

If it's not doing what it should have been doing, then the way to debug that is to watch for where it stops doing what it should


#9

thanks for your help i really apreciate it iam going to check back tomorrow


#10

I tried using this code and it worked

def purify(num):
new_list=[]
for n in num:
if n%2==0:
new_list.append(n)
return new_list
print purify([1,55,4])


#11

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