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

jamie threadgold
jamie threadgold
925 Points

Problem with code from previous task (Task 1 is no loger working). I've not changed anything.

Hi,

I've a problem with Task 3, the code from previous task (Task 1 is no loger working?). I've not changed anything.

Is it possible it's the page or have I overlooked something.

Thanks & rgds, Jamie

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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Jamie,

That error is a bit misleading. It always means that you have introduced a Syntax Error into the code Task you are currently working on, not a previous task.

Here, you introduced a Syntax Error when opening the while loop. You are using a single equal sign to try and compare a value. But a single equal sign assigns values, it does not compare. Here you need to use a double equal sign.

But to make things even DRYer, when you are checking for a boolean, you don't need to actually have any type of comparison. You could just have the statement like this:

while start:

This is the easiest way to say "While the variable start is truthy ...

Hope that helps. Keep Coding! :) :dizzy: