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

FHATUWANI Dondry MUVHANGO
FHATUWANI Dondry MUVHANGO
17,796 Points

please help

i know this is suppose to be a simple code to get right....but i just cant seem to understand the question

even.py
def even_odd(number):
    if number == 'even':
        return True
    if number == 'odd':
        return False
Cheo R
Cheo R
37,150 Points

Hello FHATUWANI,

use

number % 2 == 0

to check if it has a remainder or not. If it does not, it is even, else it is odd.

2 Answers

FHATUWANI Dondry MUVHANGO
FHATUWANI Dondry MUVHANGO
17,796 Points

Oh ok. Will test it Thanks again Cheo, really appreciate

FHATUWANI Dondry MUVHANGO
FHATUWANI Dondry MUVHANGO
17,796 Points

thanks Cheo, i understand what you are saying, i just don't know how to put it into my code

Cheo R
Cheo R
37,150 Points

No worries. First, remember that the argument number is going to be a number passed into your function.

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

Here, you're checking if the number is even; if it is, return true, else, return false. If it is true, the return statement returns to the function caller, so no need for the second conditional because the number is either even or not.