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 trialelomaur
5,276 PointsNameError: name 'num' is not defined
I can't figure out what's wrong with my code. I keep getting the error message NameError: name 'num' is not defined. Please help.
import random
even_odd = num
num = random.seed
if num % 2 == 0:
print("True")
else :
print("False")
1 Answer
Chris Freeman
Treehouse Moderator 68,454 PointsYou have the right idea. The syntax needs to be corrected:
import random
def even_odd(num): # <-- correct function definition
# num = random.seed # <-- 'num' passed as argument
if num % 2 == 0:
return True # <-- return not print
else :
return False # <-- return not print
elomaur
5,276 PointsThanks Chris!
Albert Reel
5,555 PointsAlbert Reel
5,555 PointsYou need to set num before you use it to set even_odd