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

Mark Kohner
Mark Kohner
1,121 Points

even_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?

even.py
def even_odd(number):
  if number in even_odd % 2 == 0:
    return True
    break
  else:
    return False

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Mark,

There seems to be a couple of things here:

  1. 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 a in even_odd? I think you may be confusing an if statement with a for loop.

  2. With an if/else clause, you cannot use a break statement. If something fails the if, the break will prevent it from ever reaching the else ... 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.

:dizzy: