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

Suleiman Abdurozikov
Suleiman Abdurozikov
2,943 Points

I have not understood how to do this challange

Can any one help

even.py
import random
start = 5 
def even_odd(num):
    while True:
        num=random.radint(1, 99)
        if random.randint(1, 100) % 2 :
            print("{} is even".format(random.randint(1, 100)))
        else:
            print("{} is odd".format(random.randint(1, 100)))
        while True:
            star- =1
        return not num % 2

def even_odd(num)

1 Answer

Ryan S
Ryan S
27,276 Points

Hi Suleiman,

The even_odd function is already complete as is. You don't need to add anything to it.

The challenge is asking you to create a while loop outside of the function. In this loop you will call even_odd(num) in order to test whether "num" is even or odd. The way even_odd works is that it will output "True" if the number is even and "False" if the number is odd.

Keep in mind that the random.randint() function will most likely generate a different number every time you call it, so using it in your string formatting probably won't be the same as the number you are testing. You only need to generate a random number once in this challenge.

I'd suggest reading the challenge again and go through it line by line. It walks you through the major steps required to solve it. And don't forget about using that "start" variable you created in order to control the while loop.

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 loop

Good luck.