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

or porat
or porat
684 Points

Didn't understand that question

Hey! I choose a number that is even and i returned True exacly how is asks. what i did wrong? thanx!

even.py
def even_odd(4):
    return True

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! When defining a function/method the thing in parentheses must be a valid variable name. What the challenge instructions mean is that there will be a number sent into that function/method. You are not to send the number yourself. You can think of a parameter as a variable declaration for the scope of the function you're defining. Once the function ends, the variable will not be accessible any more. Let's take a look at some pseudo code, but I'm going to give you a valid first line here.

def even_odd(num):
    #if num is evenly divisible by two (check the hints on the instructions for the modulus operator)
        #return True
    #otherwise
         #return False

Try again with these hints in mind! Good luck! :sparkles:

or porat
or porat
684 Points

thanx jennifer!

The problem with your code is that you're not suppose to include a number, you were suppose to include a var because the number that's given isn't always going to be 4. You also should have done an if loop to check if the var is even or not by using the modulo (%) and check if it equals 1, and if so, return a boolean. Here is the correct code as explained:

def even_odd(a):
    if a % 3 == 1:
        return True
    else:
        return False

Hope this clears things out :)

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi Ammar! I've changed your comment to an answer to let the original poster be able to mark it "Best Answer" if they so desire. And while your code does pass the challenge, it will fail for certain data. If I run the number 2 through your code, it returns False. I have reported this oversight to Support.

Thank you for helping out in the Community! :sparkles:

Thank you for mentioning that out so everyone could know :)

or porat
or porat
684 Points

shukran illak ammar!

afuan ;)