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 stuck - moved the while loop
I moved the while loop. I thought I fixed the indent correctly - this is v frustrating.
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.randit(1,99)
if even_odd(rnum):
print("[]" is even".format(rnum))
else:
print("[]" is odd".format(rnum))
start -=1
1 Answer
reanimator313
6,005 PointsIndent the while loop outside the function
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: # mist ":"
rnum = random.randint(1,99) # is randint not randit
if even_odd(rnum):
print("{} is even".format(rnum)) # for placeholder use "{}"
else:
print("{} is odd".format(rnum)) # for placeholder use "{}"
start -= 1
Joelle Kruczek
1,375 PointsJoelle Kruczek
1,375 PointsI fixed the errors that you pointed out, thank you. But I still get - the first = IMPORT RANDOM - Task 1 is no longer passing.
I saw references to moving the while loop under the function, and I thought with the indents that this is what I did. now I am confused.
reanimator313
6,005 Pointsreanimator313
6,005 PointsI edit my post. "randint" not "randit". I did not see that :)
Joelle Kruczek
1,375 PointsJoelle Kruczek
1,375 Pointsimport 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
am still getting the Task 1 not found error
reanimator313
6,005 Pointsreanimator313
6,005 Pointsyour code
my code
the placeholder don't need special quotes
Joelle Kruczek
1,375 PointsJoelle Kruczek
1,375 Pointsif I change to
if even_odd(rnum): print("{} is even".format(rnum)) else: print("{} is odd".format(rnum))
I get the Bummer! Wrong number of prints. error.
reanimator313
6,005 Pointsreanimator313
6,005 PointsI tried this code and it works