Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
231,269 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.