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 trialbehar
10,799 PointsPython basics, even or odd
Pretty sure my error is with trying to make number == float, but im not sure how to do it otherwise?
def even_odd (number):
if number%2 == float:
return False
else:
return True
2 Answers
Steven Parker
231,236 PointsYou 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
sradms0
Treehouse Project Reviewer 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.
behar
10,799 Pointsbehar
10,799 PointsThats really clever. ty!
sradms0
Treehouse Project Reviewersradms0
Treehouse Project ReviewerI didn't want to scare anyone...i was going to mention that