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

selcuk baran
selcuk baran
3,526 Points

What is wrong with the 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>=0:
    a=random.randint(1,99)
    if even_odd(a)=True:
        print ('{} is even').format(a)
    else:
        print('{} is odd').format(a)

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

3 Answers

if even_odd(a) = True:

On the line above Python caused an error because Python thought you wanted to assign the variable even_odd(a) to True, since you used one equal sign. To fix this use two equal signs like this:

if even_odd(a) == True:

Good luck! ~alex

selcuk baran
selcuk baran
3,526 Points

Thanks. I tried it but not a solution yet

Can you post the challenge task please?

Try doing the .format() stuff inside the print function also :)

Change this:

print ('{} is even').format(a)

Into this:

print ('{} is even'.format(a))

And do this for the other prints also.

Good luck! ~alex

NOTE: You must do this and the other answer above :)