Python Python Basics (2015) Number Game App Even or Odd

Python basics, even or odd

Pretty sure my error is with trying to make number == float, but im not sure how to do it otherwise?

even.py
def even_odd (number):
    if number%2 == float:
        return False
    else:
        return True

2 Answers

Steven Parker
Steven Parker
176,597 Points

You could just test the remainder for 0. But you can make this one really compact if you recall that 0 is "falsey" and any other number is "truthy". So if you just return the opposite ("not") of the remainder:

def even_odd (number):
    return not number % 2

Thats really clever. ty!

I didn't want to scare anyone...i was going to mention that

 if number%2 == 0:

You want to replace float with 0. If a number is even, diving that number by two would have no remainder. e.g 4 % 2 = 0, since four is an even number.