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!

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

Question about an exercise that asks me to create an odd_even function

The question asks me to create a function called odd_even that takes one parameter that is a number, and check if that number is even or odd. If even return True, if odd, return False. I created the following function which works fine in Visual Studios Python IDE. But I got "Bummer" when I checked my work Perhaps Treehouse wanted me to use the keyword return instead of print. But they didn't specify that as a requirement as far as I can tell.

def even_odd(num): if(num%2 ==0): print("True") else: print("False")


1 Answer

There are a couple things preventing you from getting it right:

One is you shouldn't be using parenthesis in your if statements in Python. Number two: Your logic looks good, however the assignment tells you to "return" the result, not print the result. You were real close though :)

In case you still don't understand here is my code:

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