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 trialAdam Evans
4,501 PointsI'm not sure what is going on. It keeps telling me Task 1, which was to define the random library is no longer working?
How is it not working if it is the first line?
import random
def even_odd(num):
# If % 2 is 0, the number is even.
# Since 0 is falsey, we have to invert it with not.
return not num % 2
#############
start = 5
while start != 0:
randomNumber = random.randint(1, 99)
if even_odd(randomNumber) = 1:
print("{} is even").format(random_number)
else:
print("{} is odd").format(random_number)
start -= 1
1 Answer
Steven Parker
231,275 PointsAny syntax error will cause the re-validation of previous tasks to fail. There appear to be several issues involved:
- the result of calling the "even_odd" function cannot be the target of an assignment
- the "format" is being applied to the result of calling "print" instead of to the template string
- the new variable is named "randomNumber" but there are references to "random_number"
And a couple of extra hints:
- you can test the result of calling "even_odd" directly, you don't need to compare it with anything
- similarly, you can check the "truthiness" of "start" without comparing it to anything