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

tangtai chen
tangtai chen
4,844 Points

I don't understand what it asked for, i coded as much as i understood can someone help?

Here is my code, and here is some of the things i don't understand:

"Make a while loop that runs until start is falsey." start is defined as a number, where do i put it to falsey?

"putting the random number in the hole." does this means adding all the even numbers?

"Finally, decrement start by 1." so i can do start - 1, and turn start to falsely, i don't konw what it is asking for can someone help?

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 True:
    num = random.randint(1,99)
    if even_odd(num) == False:
        print("{} is odd".format(num))
        start = start - 1
        print("{} is even".format(num))

1 Answer

Christopher Shaw
.a{fill-rule:evenodd;}techdegree seal-36
Christopher Shaw
Python Web Development Techdegree Graduate 58,248 Points

You are on the right track, but have slightly misunderstood the question.

The while loop should always run 5 times, not break out when it receives an odd number. So remove break and move start = start - 1 to the end, outside the if else block.

You will also need to change the while statement to while start > 0

tangtai chen
tangtai chen
4,844 Points

thx for the help, i got it right!