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

Alejandro Byrne
Alejandro Byrne
2,562 Points

Error says "Oops! it looks like Task 1 in no longer working!", why? Don't know what I'm doing wrong.

Can someone help me with my code? Not sure what is making it not work...

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

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Your code is very close. "Task 1 no longer passing" indicates an introduced syntax error.

:point_right: The condition statements need to use compare ("==") and not assignment ("=").

:point_right: start (a number) will never be equivalent to True, but it can be "truthy". When checking if start is "truthy", simply use while start.

Alejandro Byrne
Alejandro Byrne
2,562 Points

Thanks! it worked. I knew about the '==' just forgot how to check for 'truthy'.

First of all, start is never either True or False. It is "truthy"... It's kind of weird, but the simple answer to line 10 is to remove the = True part.

Keep in mind that 0, None, an empty string, an empty list, and other empty things are falsey and all other values (except booleans) are truthy.


Line 12 where it says if even_odd(num) = True: is causing a Syntax error as well. Python thinks you are trying to assign a variable called if even_odd(num) to the value of True. But, of course, you are trying to compare values. TO test equality you should use the double-equals operator (the equality operator). It looks like this: ==

I hope this helps. If you continue to fail, please respond. Thanks! ~Alex