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

task 1 is no longer passing

i don't see any wrong with the code on task 3

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

4 Answers

There is a single typo in here.

number = random.randit(1, 99)
# should be
number = random.randint(1, 99)

I would do: while start != False and also if even_odd() = True/False

Having even_odd return a bool type wouldn't be a bad idea, but I don't think that while start != False is going to work. He has it as a number the is being decremented, so it stops when the number becomes falsey, but changing it would result in the number needing to be False to stop. I don't think that's necessary.

while bool(start) != False:

would work, but

while bool(start) is not False:

would still be a better solution than !=.

But isn't False == 0? Do we need to use bool() function?

Correct. I had gotten confused. False == 0 returns True. What confused me is that False is 0 returns False.

Yeah. Coz "is" is sth different than "==".