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

Oscar Chong
PLUS
Oscar Chong
Courses Plus Student 292 Points

Pls help me out

the question is :

Write a function named even_odd that takes a single argument, a number.

return True if the number is even, or False if the number is odd.

You can use % 2 to find out the remainder when dividing a number by 2. Even numbers won't have a remainder..

Can you pls tell me what should i do? Thanksss

even.py
def even_odd(num):
    while True:
        if num == even:
            return True
        else:
            return False

1 Answer

You need to use % to find out if a number is odd or even. What % does is find the remainder of a division calculation; for example 9 % 4 = 1 . This is because 9 divided by 4 is 2 REMAINDER 1. All even numbers % 2 = 0. And all odd numbers % 2 = 1. E.g 6% 2 = 0 and 5 % 2 = 1. You can wright an if statement to check if num % 2 = 0 or 1. If it’s 0 then it’s even and you can return False if it’s 1 then you can return True.

Try and attempt to do the chanllenge on your own, but I’m going to leave my code below.

def even_odd(num):
    if num % 2 == 0:     #even
        return False
    if num % 2 == 1:    #odd
        return True