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 trialjack twist
Full Stack JavaScript Techdegree Student 18,575 PointsI don't understand why it's saying is_odd(2) returns True, why my code doesn't work?
def is_odd(x):
if int!=x/2:
return True
1 Answer
Megan Amendola
Treehouse TeacherHi 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
561 PointsMichel Baute
561 PointsI spent ages on this problem. The code Jack Twist used is correct, just the formatting is wrong. This worked for me: