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 trial

Python Python Basics (2015) Letter Game App Even or Odd Loop

Karl Long
Karl Long
1,661 Points

Make 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?

even.py
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
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi 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! :sparkles:

Karl Long
Karl Long
1,661 Points

Hi 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))