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

Pincemail Sebastien
PLUS
Pincemail Sebastien
Courses Plus Student 2,411 Points

hello , could some one can tell me what's wrong with my loop

i got the result i was waiting for in the console but maybe i miss something.

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

1 Answer

Russell Sawyer
seal-mask
.a{fill-rule:evenodd;}techdegree
Russell Sawyer
Front End Web Development Techdegree Student 15,705 Points

Your print statements need to be formatted correctly.

The while loop needs to be out dented and outside of the function to work correctly.

The start = 5 needs to be outside the function as stated in section 2 of 3 of this challenge.

import random

start = 5

def even_odd(num):
    return not num % 2

while start:
    random_number = random.randint(1,99)
    if random_number % 2 == 0:
        print("{} is even".format(random_number))
    else:
        print("{} is odd".format(random_number))
    start -= 1

But overall you have all the code you need on the page it just needs to be re organized. :)

.