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

My Python challenge returning SyntaxError: invalid syntax, but it runs correctly in Workspace, what am I doing wrong?

The Challenge question: Challenge Task 1 of 1 Let's create a function that determines if a specific value is odd. Let's name the function is_odd and have it declare a single parameter. It should return True if the value is not divisible by 2.

My Code

def is_odd(number):
    number =int(number)
    if number % 2 != 0:
        return "true"

The error: Bummer: SyntaxError: invalid syntax Task #1 .---------------------------------------------------------------------- Ran 1 test in 0.000s OK

.F

FAIL: test_odds (main.TestFunctionDefinitionExecution)

Traceback (most recent call last): File "", line 54, in test_odds

AssertionError: None is not true : Uh oh, 1 is odd but is_odd(1) returned False.

Ran 2 tests in 0.000s

FAILED (failures=1)

1 Answer

True is a boolean value and shouldn't be enclosed in quotes. That makes it a string. Try:

return True