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 trialMark Kohner
1,121 Pointseven_odd function stuck
def even_odd(number): if number in even_odd % 2 == 0: return True break else: return False
I am stuck here, getting only 'bummer try again' to direct me towards the solution, I have tried many variations but I am not having any luck on identifying where I am stuck. I am confused on the use of the random replacements for the parameters as well, do I need to introduce a new obscure variable somewhere, or is this mostly correct? Do I use if number % 2 == 0, a form of this, or do I need to introduce new pieces?
def even_odd(number):
if number in even_odd % 2 == 0:
return True
break
else:
return False
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHey Mark,
There seems to be a couple of things here:
The
if statement
should be checking to see if the (number % 2) is equal to zero. This should return a boolean. I'm not sure why you have include ain even_odd
? I think you may be confusing anif statement
with afor loop
.With an
if/else
clause, you cannot use abreak
statement. If something fails theif
, the break will prevent it from ever reaching theelse
... so incorrect syntax.
Below is the corrected code for you reference. I hope it will make sense. :)
def even_odd(number):
if (number % 2) == 0:
return True
else:
return False
Now, the if statement
is checking the formula against the number passed into the method. If the result is zero, it will return true and execute the return True
. If the result is false, the code in the else
clause will execute instead.