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

natalie fairbourne
natalie fairbourne
1,466 Points

I need help with challenge 3 of 3

I am unclear with what I am trying to write. I'm not sure how start=5 and reducing it by 1 comes into play. Can some show me the solution and explain it to me?

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

1 Answer

Ryan S
Ryan S
27,276 Points

Hi Natalie,

The key with this one is that you don't modify the even_odd() function. It has already been written for you and is complete as it is. It returns True if a number is even, and False if it is odd.

You need to create a while loop outside of the function, and call even_odd to test your random integers.

Instead of giving the answer, here is a guide on how to set up your code. I think you'll be able to solve it from here.

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:
    #Code goes here

    start -= 1

To answer your question about the start variable, each time the while loop runs, start will decrement by 1. Evenutally, it will equal 0 and the while condition will evaluate to False, which will end the loop.

Hopefully this gets you started. If you still need more help let me know.