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.

marinmirosevic
3,279 Pointswhats wrong here?
whats wrong here?
thanks
number=6
number_1=number/2
def even_odd(number):
if int(number_1)==number_1:
True
else:
False
2 Answers

Steve Hunter
57,682 PointsHi 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.

marinmirosevic
3,279 Pointsthaks Steve
