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

Jonathan Camacho
Jonathan Camacho
1,504 Points

I cannot grasp what is wrong, please help.

I tried to condition that if it was a whole number, without remainders, then it would be even. So I came up with this. However, it says that it did not have the correct answer.

even.py
def even_odd(number):
    if number is int:
        return True
    else: 
        return False
peter Bowden
peter Bowden
369 Points

Click this link https://teamtreehouse.com/perkrlsn or read the below comment as he explains how to solve the problem buddy keep it 100!

3 Answers

Hi Jonathan!

You need to use the module operator (%). When you divide a number by 2 and the residue is 0, it means that number is even. If is not 0 so the number is odd. Here the module operator y very helpful.

Try this:

even_odd.py
def even_odd(number):
    if number % 2 == 0:
        return True
    else:
        return False
Per Karlsson
Per Karlsson
12,683 Points

Hi @jonathancamacho2,

Try this instead

...
if type(number) is int:
...

Cheers, Per

Jonathan Camacho
Jonathan Camacho
1,504 Points

It did not work. View the challenge please

Per Karlsson
Per Karlsson
12,683 Points

Hi Jonathan,

I thought this was a general question with type comparison. My bad. See Emmanuel's answer below.

Good luck!

peter Bowden
peter Bowden
369 Points

Buddy you just need to read the principals the course gives you to follow and fix or correct them you will be fine comments like the one you made are invalid ('Like the way I did that ;)') you will be fine think for a little before making a question as know it all's myself jump onto the subject like animals haha happy coding broski ;)