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 trialKarl Long
1,661 PointsMake a while loop that runs until start is falsey. Inside the loop, use random.randint(1, 99)
what am i doing wrong here? I am not sure of the relevance of Start in this task?
import random
start = 5
while False
num = random.randomint(1, 99)
def even_odd(num):
if num % 2 == 0:
Print("{} is even".format(num))
else:
Print("{} is odd".format(num))
start -= 1
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! The start
variable is mission critical here as the challenge requires (as indicated by the instructions) that the while loop run until start
becomes "falsey". Here's a hint: start
will become falsey when it reaches a value of 0. If you want something to run while the value is not "falsey" you can accomplish it like this:
while(myVariable):
#do this code while myVariable is not falsey
Using this hint, check to see if start
is falsey or not. Note: do not change the original value of start outside of your while
loop. Your start
value will need to be changed inside the while loop to make sure you don't end up in an endless loop.
I feel confident that you can get it with these tips, but let me know if you're still stuck!
Karl Long
1,661 PointsKarl Long
1,661 PointsHi Jennifer, any more pointers on the below?
import random
start = 5 num = random.randomint(1, 99)
while start > 0: start -= 1 def even_odd(num): if num % 2 == 0: Print("{} is even".format(num)) else: Print("{} is odd".format(num))