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 Practice Creating and Using Functions in Python Practice Functions That's Odd

I don't understand why it's saying is_odd(2) returns True, why my code doesn't work?

create_a_function.py
def is_odd(x):
    if int!=x/2:
        return True

1 Answer

Megan Amendola
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher

Hi jack twist !

If you haven't already, I would suggest opening up a python workspace and playing around with your function. For instance, I ran this:

def is_odd(x):
    if int!=x/2:
        return True


print(is_odd(2))
print(is_odd(1))
print(int)

# Console
>>> True
>>> True
>>> <class 'int'>

Right now your function is checking if <class 'int'> does not equal the number passed in x divided by 2. This will always be true because they will never be equal

Michel Baute
Michel Baute
561 Points

I spent ages on this problem. The code Jack Twist used is correct, just the formatting is wrong. This worked for me:

def is_odd(x):
    if int(x % 2 != 0):
        return True