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

Kade Carlson
Kade Carlson
5,928 Points

Wrong number of prints?

It says I have the wrong number of prints...I'm also not sure what it's asking me to do when it says "decrement start by 1"

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

1 Answer

Steven Parker
Steven Parker
231,007 Points

You loop condition is not correct.

You wrote "while start < 5:", but since start is set to 5 to begin with, this is not true so the loop would never run. Also, you can test something for "falsey" just by naming it, you don't need to compare it to anything.

Then later, you wrote "if number % 2 == 0:", which essentially re-creates the even_odd function. You could just call that function as the if condition and pass it number as the argument.

The line with "even_odd()" by itself doesn't do anything, plus it probably causes a syntax error because it doesn't pass any argument to the function.

And "decrement start by 1" would likely be implemented with this code:

    start -= 1