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

Brian S.
Brian S.
3,176 Points

Hmmm... any suggestions? Code is doing as I expect, still not getting answer correct.

i also tried altering the Else to: else num % > 0 : print('False') break

even.py
def even_odd(num):
    while True:
        if num % 2 == 0:
            print('True')
            break
        else:
            print('False')
            break

2 Answers

Hey there!

1) Remove the loop and "break" statements-- You don't need to check if a number is odd or even more than once

2) Don't print true or false, use return instead :D -- This is how you get the value out of the function for reuse, rather than just showing the answer on the screen.

Your use of the modulo function is spot on though!

Brian S.
Brian S.
3,176 Points

wow, i was doing way too much. Thank you

Kristian Gausel
Kristian Gausel
14,649 Points

I dont understand why you use a loop. Also it says you should return true or false, not print it. The code looks something like

def even_odd(num):
    return num % 2 == 0
Brian S.
Brian S.
3,176 Points

I dont understand why i used a loop either, in hindsight. Thank you