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 trialLogan Valdez
Courses Plus Student 6,741 PointsHow Do I Fix This?
Hello. In this challenge I am supposed to import random in Task 1, but when I try and submit my code it states that Task 1 is no longer passing. What can I do to fix this?
import random
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
start = 5
while True:
if start == False:
exit()
a = random.randint(1, 99)
if even_odd(a):
print("{} is even".format(a)
else:
print("{} is odd".format(a)
print(start - 1)
1 Answer
Chase Stevens
11,056 PointsHi Logan,
This is close! There are some changes to make to the while loop that will make your code fly.
- You can change the while declaration to "while start" -- since start is not zero, it is True, and when it reaches zero, it will evaluate as false. This will also take care of the first two lines of code in the while loop.
- Where you're trying to decrease the value of start, you are actually printing the expression "start - 1", which does not assign a new value to start. Once you change this expression, you'll be gold!
Please let me know if you have any questions and I'll be happy to help.