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 trialRichard Farr
4,857 Pointsbug - import random
The error message says task 1 - import random - no longer works but its clearly at the top of the code.
Is this a bug?
also, pointers would be appreciated on the next steps... why isn't this working?
import random
start = 5
while (start>0):
randnum = random.randint(1, 99)
oddeven = even_odd(randnum)
print ("{} is {}".format(randnum,oddeven))
start = start -1
def even_odd(num):
# If % 2 is 0, the number is even.
# Since 0 is falsey, we have to invert it with not.
if num % 2 == 0:
return even
else:
return odd
1 Answer
Steven Parker
231,248 PointsThe message may be a bit misleading.
But it's because you've introduced a few errors in the program:
- you reference even_odd before it is defined
- inside even_odd you reference even and odd, and neither have been defined.
You could fix these and pass the challenge, but I don't think the challenge actually intended for you to modify the even_odd function. For task 3, you should write new code that makes use of the even_odd function as it was originally provided to satisfy the requirements.