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 trialMykiel Horn
4,014 PointsCan anyone tell me what is wrong with the else part of my loop?
The challenge keeps telling me that task one isn't passing, which is creating the start variable and assigning 5 to it. When I placed all of my code into the workspace I received a SyntaxError for the line where the else is.
import random
start = 5
def even_odd(num):
# If % 2 is 0, the number is even.
# Since 0 is falsey, we have to invert it with not.
while True:
ran_num = random.randint(1,99)
if ran_num % 2 == 0:
print("{} is even".format(ran_num)
else:
print("{} is odd".format(ran_num)
start -= 1
return not num % 2
2 Answers
Steven Parker
231,269 PointsA syntax error invalidates the entire script and causes the re-testing of earlier tasks to fail. Take a closer look at your "print" statements.
Also, you should not modify the provided "even_odd" function for this challenge. The code you write for task 3 should come after the function. But you will find it handy to use the function in creating your code.
nakalkucing
12,964 PointsHi there! I would suggest taking a look at your parenthesis.
Steven Parker
231,269 PointsSteven Parker
231,269 PointsWould the downvoters please explain what I might change to make my hints more useful (without leaving explicit spoilers, I don't want to do that).