Is even or odd


I don't feel like the code should be doing this, it feels kind of reverse.

So I'm testing for it to be even in line six, but it kept returning odd numbers. I switched it to saying anything true to that( if i % 2:) is now not wanted and the rest is. I feel like it shouldn't work like this. Could anyone explain this to me?

def purify(numbers):
    n = numbers
    accepted = []
    denied = []
    for i in numbers:
        if i % 2:
    print accepted
    return accepted


To achieve a check for even-ness, it should be that the modulus 2 of that number should have no remainder - zero (0). So, I can suggest that you do:

if i%2 == 0:

Hope this helps answer your question! :wink:


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