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 trialJoelle Kruczek
1,375 Pointsstill Task 1 redo error. please help - Even Odd loop for challenge 3 of 3
I still get the Task 1 redo error. am at a loss - please help
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:
rnum = random.randint(1,99)
if even_odd(rnum):
print(""{}" is even".format(rnum))
else:
print(""{}" is odd".format(rnum))
start -=1
Joelle Kruczek
1,375 PointsAm all set - thanks everyone for your help!
Krishna Pratap Chouhan
15,203 PointsJoelle Kruczek , what was the problem?
1 Answer
rydavim
18,814 PointsKrishna Pratap Chouhan and anyone else who ends up finding this via search -- it looks like the following two things were the problem.
import random
start = 5
def even_odd(num):
return not num % 2
# This whole while loop needs to be outside the even_odd() function block.
# It should be inline with import, start, and def even_odd().
while start:
rnum = random.randint(1,99)
if even_odd(rnum):
print(""{}" is even".format(rnum)) # Here, the {} placeholder brackets need to be part of the string, not outside it.
else:
print(""{}" is odd".format(rnum)) # The same goes for here - it should be "{} is odd".format().
start -=1
I suspect those were the items he figured out after your comment. Happy coding, everyone!
Krishna Pratap Chouhan
15,203 PointsKrishna Pratap Chouhan
15,203 Pointsindentation of 'while' block needs addressing, but i am not sure if that would solve the problem.