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

Can someone give me a hint please. I'm a little stuck.

How do I do the function so if it's even it's True and not It's False.

even.py
import random

start = 5

def even_odd(num):
    # If % 2 is 0, the number is even.
    if num % 2 = 0:

    else:

    # Since 0 is falsey, we have to invert it with not.
    return not num % 2

while True:
    num = random.ranint(1,99)
    if even_odd = 0:
        print" {} is even".format(num)
    else:
        print(" {} is odd".format(num)

2 Answers

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

You should not change anything in the even_odd function.

if even_odd(number):  # even_odd(1) returns False / even_odd(2) returns True

I hope this helps :-)

Hi. Since you're asking for a hint, I'll try to nudge you in the right direction with a couple observations here:

  1. All of your conditions here are using the single equals sign. However, that is used to assign values to variables as in v = 3. To compare a value to another, you'll need the double equals sign as in if x % 2 == 0:.

  2. Nothing is actually taking place as a result of your if...: else:... structure inside the even_odd(num) function.

  3. The method for getting a random integer using the random module is random.randint() as opposed to random.ranint().

  4. You're not calling your even_odd function on line 16 since there are no parentheses, and be sure to call it with an argument to be passed to the num parameter you define for it.

  5. You don't define a break statement inside your while True: loop so you're ending up with an infinite loop.

Hope this helps!