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

It looks like task 1 is no longer passing?

Im not sure i entirely understand what i have to do here?

even.py
import random
start = 5
def even_odd(num):
    while start == True:
        num = random.randint(1, 99)
        test = num % 2
        if test == True:
            print("{} is odd".format(test))
        else:
            print("{} is even".format(test))
        test - 1
    # If % 2 is 0, the number is even.
    # Since 0 is falsey, we have to invert it with not.
even_odd()

2 Answers

Steven Parker
Steven Parker
230,995 Points

Yea, you got off the track a bit here.

You won't need to make any changes to the provided "even_odd" function. All your work will be added outside of the function, but you can make use of the function in your code to test a number to see if it is even or odd.

Also, remember to modify "start" since you're using it to control the loop. And you don't need to compare anything with "True", just naming it serves as a test of "truthiness".

I now made this code, but i still dont get what im missing, and i didnt understand what you meant by "just naming it servres as a test of thruthiness". I dont know any other way to if the number is true or false?

import random
start = 5
while start != 0:
    if number % 2 == False:
        print ("{} is even".foramt(number))
    else:
        print("{} is odd".foramt(number))
    start - 1

def even_odd(num):
        number = random.randint(1, 99)
    # If % 2 is 0, the number is even.
    # Since 0 is falsey, we have to invert it with not.
    return not num % 2

nvm i figured it out! Ty dude

Steven Parker
Steven Parker
230,995 Points

Congrats! :+1: For the benefit of others reading this, what I meant by "just naming it" is this:

while start:  # instead of "while start != 0"