Okay, so I feel really stupid, but for some reason my code isn't working.

Oops, try again. is_even(19) returned True instead of the expected: False

It's supposed to check to see if a number is even.

Replace this line with your code. 
def is_even(x):
    if x % 2:
        return True
        return False


This is saying, "If x modulo 2 is non-zero" which would make x odd. Switch your booleans around and it will be correct logic.


if x % 2

I don't see any conditionals comparator statement that is returning boolean : True/False

like, suppose I wanted to check if x is even then I'd have checked like this..
x % 2 == 0`

I hope you get the hint! :slight_smile:
Do reply if it has solved your problem !


got it thanks.
Man I feel like an idiot.


Keep up the good work and It happens!!! :thumbsup:


Don't you?

if x % 2:
    return False

x % 2 is truthy if it is non-zero. There is nothing wrong with writing it this way. That's why I suggested switching the booleans around and leave the rest alone. It is just as valid, and also correct.

In truth, for something as trivial as testing parity, this would be the most straight forward approach:

>>> def is_even(x):
    return not x % 2

>>> is_even(42)
>>> is_even(33)


Yeah, I made a mistake in observation! I've updated my answer!
:slight_smile: :thumbsup:


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