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 trialFHATUWANI Dondry MUVHANGO
17,796 Pointsplease help
i know this is suppose to be a simple code to get right....but i just cant seem to understand the question
def even_odd(number):
if number == 'even':
return True
if number == 'odd':
return False
2 Answers
FHATUWANI Dondry MUVHANGO
17,796 PointsOh ok. Will test it Thanks again Cheo, really appreciate
FHATUWANI Dondry MUVHANGO
17,796 Pointsthanks Cheo, i understand what you are saying, i just don't know how to put it into my code
Cheo R
37,150 PointsNo worries. First, remember that the argument number is going to be a number passed into your function.
def even_odd(number):
if(number % 2 == 0):
return True
return False
Here, you're checking if the number is even; if it is, return true, else, return false. If it is true, the return statement returns to the function caller, so no need for the second conditional because the number is either even or not.
Cheo R
37,150 PointsCheo R
37,150 PointsHello FHATUWANI,
use
number % 2 == 0
to check if it has a remainder or not. If it does not, it is even, else it is odd.