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

Didier Borel
Didier Borel
2,837 Points

return true or false,

I don't understand why I get this error message. I believe I am doing what is being asked. what is wrong. subsidiarily, if I define number =random.randint(1,50) instead of num=random.randint(1,50), I also get an error message. I don't understand why neither. isn't num, or number just simply a variable I define myself?

thanks.

even.py
import random
num=random.randint(1,50)
def even_odd(num):
  if (num % 2)==0:
    print("True")
  else:
    print("False")

2 Answers

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

You're doing really well! But no, you're not doing what they asked. They explicitly asked you to return the values true or false. You're printing out the strings "True" or "False" and now they can't evaluate your code. Take a look at what the challenge needs:

import random
num=random.randint(1,50)
def even_odd(num):
  if (num % 2)==0:
    return True
  else:
    return False
Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Didier Borel Woops! I missed the second part of your question. I don't know what error you were getting , but if I change "num" to "number" it works. However, if you change num to number you have to change it everywhere it says num. The resulting code would look like this:

import random
number=random.randint(1,50)
def even_odd(number):
  if (number % 2)==0:
    return True
  else:
    return False

So, my best guess is that you had a typo somewhere.