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 trialHarper Frankstone
5,156 PointsEven_Odd function will work in Workspaces, but not in the Challenge
I am writing a while loop that iterates for as long as the counter variable is True. The loop is supposed to get a random number between 1 and 99, then pass that number into a function that evaluates whether it is even or odd. Once the function finishes, an if statement is supposed to print out statements, saying whether the number is even or odd. I can get this code to work in my workspaces, but it is not acceptable to the code challenge. I don't know about this one, please help!! Thanks!
import random
start = 5
def even_odd(num):
# If % 2 is 0, the number is even.
if num % 2 is 0:
# Since 0 is falsey, we have to invert it with not.
return not num % 2
while start:
num = random.randint(1, 99)
even = even_odd(num)
if even:
print("{} is even.".format(num))
else:
print("{} is odd.".format(num))
start -= 1
1 Answer
Steven Parker
231,275 PointsThe challenges are very picky about returned strings.
You apparently added some punctuation (periods) that was not asked for in the instructions. It looks nice, but it makes the challenge checker think the output is wrong.
Harper Frankstone
5,156 PointsHarper Frankstone
5,156 PointsHey Steven,
Thanks for your comment, but could you be a bit more specific? I'm not seeing any extra periods, or punctuation that is unnecessary..
Steven Parker
231,275 PointsSteven Parker
231,275 PointsHere's one of them. The challenge asked for "{} is even" (with no period), but you wrote this: