Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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")

even.py

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
    else:
        return False