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

I can't find my error.

It tells me "task 1 is no longer complete" - task 1 is to import random which i haven't changed. What am I missing?

even.py
import random



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

start = 5

while start:
    new_num = random.randint(1,99)
    if even_odd(rnd):
        print("{} is even".format(new_num))
    else:
        print("{} is odd".format(new_num))
    start -=

1 Answer

Wade Williams
Wade Williams
24,476 Points

You're pretty close on this one. I'm not sure why it's says task 1 is no longer passing, but I do see some errors in your code. You're passing in "rnd" into your even_odd function and this should be the new_num variable you created and then when you decrement "start" you need to specify start -= 1. When I make these changes your code passes.

All together now

import random

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

start = 5

while start:
    new_num = random.randint(1, 99)

    if even_odd(new_num):
        print("{} is even".format(new_num))
    else:
        print("{} is odd".format(new_num))

    start -= 1

Ahh, thank you very much. The rnd variable is a residual of the original variable which I changed in hopes to fix the error.

I think the fix on my decrements is what the real issue was. Thank you for your help