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

whats wrong here?

whats wrong here?

thanks

even.py
number=6
number_1=number/2    
def even_odd(number):
    if int(number_1)==number_1:
        True
    else:
        False

2 Answers

Hi there,

You just need to create the method here; don't worry yourself about declaring variables outside of the method.

You want to return True if a number is even. To test for this, use the mod operator, the % symbol. An even number will give zero with a_number % 2. The a_number variable is passed into the method as a parameter; you don't need to declare it outside of the method.

So, that gives us an if clause:

if a_number % 2 == 0:
  return True

This is mutually exclusive, so the else: part writes itself; there can only be two outcomes:

if a_number % 2 == 0:
  return True
else:
  return False

Now we just need to put that in a method that takes a parameter (and sort the indenting):

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

That should do it for you!

Steve.

thaks Steve

:+1: