Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Letter Game App Even or Odd Loop

"Task 1 is no longer passing"


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

def main()
while start:
    ri = random(randint(1,99))
    if even_odd(ri) == True:
        print "{} is even".format(ri)
        print "{} is odd".format(ri)    
    start -= 1


3 Answers

james south
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,258 Points

you are doing things the challenge does not ask for. it just asks for a while loop, not a function, so the empty function body, missing colon, errant return statement and call to main() are throwing errors.

Appreciate the reply, James, thanks. I wrapped the code in a function to begin with because I was getting that error even w/o wrapping in a function and just thought I'd try. I get frustrated sometimes w/ these challenges because whenever I get that error "task 1 is not longer passing" - it's very obtuse and I can't figure out what's causing it, and I usually have to roll back and start all the challenge questions over. The challenge instructions are usually concise enough so that I don't run into this problem, but it's pretty maddening when it happens. Just venting...

thanks again - paul

james south
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,258 Points

it often says that when you introduce an error in the current task. it rarely if ever is actually because your code from a previous task is suddenly not acceptable any more. you don't have to start over.