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) Number Game App Even or Odd

not sure what I'm missing (again)

so I've:

1) made the function even_odd with number as it's argument 2) defined number so the value would equal either 0 (even) or 1 (odd) 3) created an if loop that returned True for 0 and False for 1 4) called the function - I'm still not clear when I should be doing this and when I shouldn't - some of the code in the tasks and videos have done it both ways in different situations and I'm not sure what determines its necessity.

even.py
def even_odd(number):
    number = int(5) % 2
    if number == 0:
        return True
    else: 
        return False

even_odd(5)

1 Answer

Todd Anderson
Todd Anderson
4,260 Points

Hi.

For this challenge you can pass your argument into a conditional instead of creating a new variable. Also in python you don't need to specify that a number is an int, it will figure that out when the code is run. Try this.

def even_odd(nums):
    if nums % 2 == 0:
        return True
    else:
        return False