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

Challenge crashing

Have tested the code in the workshop and it runs continuously becasue start is never falsey. This keeps crashing the challenge so it can't be completed. I believe I'm not understanding the part where it says to decrement start by 1. This would make the while statement run continuously, would it not?

even.py
import random

start = 4

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

1 Answer

AJ Salmon
AJ Salmon
5,675 Points

The challenge says to set start to 5, then run the while loop until it's falsey, or equal to zero. You're using the even_odd function on start, which is not what it asks to do in this one. Your while should look like this:

while start:

Simple as that. The reason we don't write while start is true is that is checks for equality, and start does not equal True, but it's Truthy, which I know can be confusing, haha. Decrementing start by 1 each time the loop runs will eventually make start = 0, at which point the loop will break. You can do this by adding start = start - 1 or start -= 1. Either one works. Last thing- the strings that you print shouldn't contain periods! Hope this helps,

AJ