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

Jason Dirnbauer
Jason Dirnbauer
18,815 Points

even_odd exercise - why isn't this working? It works in Workspaces

I have created the following code for the even_odd exercise. When I put this though Workspaces it works fine. However, when I submit this as my answer the challenge doesn't like it. What's wrong? Thank you for any help.

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

even_odd(5)

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Your code is functional, but it isn't precisely what they asked you to do. They ask you to return the value true or false... not print it. If I switch out your print statement with return statements and return a boolean instead of a string, it passes! Take a look:

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

even_odd(5)
Jason Dirnbauer
Jason Dirnbauer
18,815 Points

So close yet so far away. Thank you Jennifer. I revised the code and that worked great. Thanks for the help.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

You're quite welcome! Remember, if you're sure your logic is sound... read the instructions again. We've all fallen victim to that sort of thing :)