Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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?

even.py
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
        break
    else:
        print("{} is even".format(num))

1 Answer

Christopher Shaw
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Christopher Shaw
Python Web Development Techdegree Graduate 58,236 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!