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

even_odd question is bugged?

I believe that the question evaluation for the even_odd three-part challenge is bugged and not functioning, which isn't allowing me to complete the module.

The following code compiles and completes the challenge as described, and passes the first two tests, when I add the while block to the code for step three, it starts complaining that step one no longer passes, even though I haven't changed the code and it compiles and runs in work spaces.

Code:

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 != False: rand = random.randint(1,99) if even_odd(rand) == True print("{} is even".format(rand)) else: print("{} is odd".format(rand))

start = start-1
even.py
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 != False:
    rand = random.randint(1,99)
    if even_odd(rand) == True
        print("{} is even".format(rand))
    else:
        print("{} is odd".format(rand))

    start = start-1

1 Answer

Steven Parker
Steven Parker
229,645 Points

You have a syntax error.

You forgot to put the colon (":") at the end of your if line. That really worked in the workspace?

Also, while it's not an error, you never have to compare a boolean to True. Just naming it is enough.

Yeah I found that in one editor and not the other right after I posted this... unfortunately the in-tutorial doesn't return a useful error when trying to run the script, while workspaces does.