Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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: