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

Damian McCarthy
Damian McCarthy
3,656 Points

I have no idea how to even think about this one.

I don't know where to start.

even.py
def even_odd()
    if a%2:
        return True
    else:
        return False

2 Answers

AJ Salmon
AJ Salmon
5,675 Points

Hey Damian!

You're on the right track. First, though, you need to make sure that your function takes an argument, so you give it a placeholder argument when you create it. This is called setting the parameters, and it looks like this:

def even_odds(num):
#you can name this placeholder anything you want, 
#it's just somewhat conventional to use 'num' when
#you know that the argument will be a number

On a side note, if your function needed to take two arguments, for example, you'd set two parameter arguments, like this:

def add(num1, num2):

Alright, now we need to test and see if this number has a remainder when it's divided by 2. As the challenge mentions, you can use the % opperand to do this. If num % 2 is equal (or == in python) to 0, then it's even, and you need to return True. Otherwise, return False. I know you can do the rest by yourself, happy coding, and if you need any more guidance feel free to ask! :)

Hi Damian!

You have three errors in your code.

First of all when after you define your function, you need to add a colon. Like this:

def even_odd(): #add colon

Second, you need to give it an argument called "number" as it says to do in the challenge. Like so:

def even_odd(number): #add argument number

Finally, in your if statement, the first block of code is supposed to say that when the number, passed in by the user, is divided by two, the remainder will be 0, because that makes it an even number.

We can do this by using the modulo operator: %. If we say:

if number % 2 == 0:

Other than that your code is fine.

Here is the final code:

def even_odd(number):
    if number % 2 == 0:
        return True
    else:
        return False

Hope this works!

If this does not, please let me know.

Thanks!