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 trialRoderick Sang
6,891 PointsTask One Stops Passing
Whenever I hit Part 3 of this question, it tells me Task 1 no longer passes. And when I try to run my code in Task 1 without changing it back, it tells me there's a syntax error that I don't see.
Can anyone tell me where I'm going wrong?
import random
start = 5
while start:
random_num = random.randint(1, 99)
if even_odd(random_num) > 0:
print("{} is even".format(random_num)
else:
print("{} is odd".format(random_num)
start--
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
1 Answer
David Axelrod
36,073 PointsHey Roderick!
even odd spits out a boolean. try just checking that on its own. Just passed with the code below. it gave me the same, 'task one is not passing' but it was just because i was originally using the '{}' % var instead of normal format
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.
return not num % 2
while start:
randnum = random.randint(1,99)
if even_odd(randnum):
print("{} is even".format(randnum))
else:
print("{} is odd".format(randnum))
start -= 1
Roderick Sang
6,891 PointsRoderick Sang
6,891 PointsThanks, David!
Admittedly I tried changing my code myself to look like yours (( that if even_odd(randnum) line ))and it didn't work, but copying and pasting your code DID work, so... I guess it's just something I wasn't seeing, hah.