Number 1 is flip-flopped!


#1

I was moving on to this lesson and I did the code it asked me to do:

def is_even(x):
    if x % 2:
        return True
    else:
        return False

I ran the code and it kept giving me an error like this: is_even(38) returned False instead of True, so I flip-flopped the True and the False:

def is_even(x):
    if x % 2:
        return False
    else:
        return True

And it worked... :expressionless:


#2

Is there a question in this?

x % 2 will be non-zero if x is odd, so it will evaluate to yield True. But we want even to be True, so the return values are reversed.

def is_even(x):
    if x % 2 == 0:
        return True
    else:
        return False

#3

It's not a question, but I did realize something. I missed the == 0 part. Thanks for showing your code. :smiley: