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

Greg Isaacson
Greg Isaacson
Courses Plus Student 702 Points

Not sure how to use even_odd??

Hi All,

A little stuck here...

Im not sure how to use the even_odd function?? this is throwing me off....

import random
start = 5
while start == True:
    random.randint(1, 99)
    (start - 1)

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

2 Answers

Don't worry about figuring out how the even_odd function works. All it does is that is returns True if the number you pass in is even or else it will return False.

we can just return the remainder of num / 2 (with num % 2), but because this returns whether a number is odd or not and the function is supposed to return whether a number is even or not, we need to reverse whatever value comes out of num % 2