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 trialPatrick Ho
1,186 Pointstask 1 is no longer passing
i don't see any wrong with the code on task 3
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:
number = random.randit(1, 99)
if even_odd(number):
print("{} is even".format(number))
else:
print("{} is odd".format(number))
start -= 1
4 Answers
jacinator
11,936 PointsThere is a single typo in here.
number = random.randit(1, 99)
# should be
number = random.randint(1, 99)
Małgorzata Staniszewska
2,431 PointsI would do: while start != False and also if even_odd() = True/False
jacinator
11,936 PointsHaving even_odd
return a bool
type wouldn't be a bad idea, but I don't think that while start != False
is going to work. He has it as a number the is being decremented, so it stops when the number becomes falsey, but changing it would result in the number needing to be False
to stop. I don't think that's necessary.
while bool(start) != False:
would work, but
while bool(start) is not False:
would still be a better solution than !=
.
Małgorzata Staniszewska
2,431 PointsBut isn't False == 0? Do we need to use bool() function?
jacinator
11,936 PointsCorrect. I had gotten confused. False == 0
returns True
. What confused me is that False is 0
returns False
.
Małgorzata Staniszewska
2,431 PointsYeah. Coz "is" is sth different than "==".