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 trialChristian Geib
826 Pointserror message Bummer! invalid syntax (<string>, line 5) even though code appears to work
Hi guys, with the help of some of you I have been able to come up with some code that does work. However, when I click on Check Work I still receive the following error message:
Bummer! invalid syntax (<string>, line 5) even though code appears to work
admitted = None
if age >= 13:
admitted = True
else:
admitted = False
2 Answers
Michael Hulet
47,913 PointsPython associates blocks of code based on how much they're indented. Furthermore, every else
keyword needs a corresponding if
keyword to go before it. That means that for every else
, there must be an if
statement before it that's indented at the same level. In your code, the else
and line within it is indented farther than the if
block above, so Python sees it as an entirely different construct that it doesn't recognize. If you put the else
on the same indentation level as the if
(and make sure the code inside the else
is also indented how it should be), the syntax error will go away.
Alexandra Barnett
Front End Web Development Techdegree Graduate 46,473 PointsHi Christian! I think it's because your else clause is indented too far - it needs to be in line with the if statement.
Hope that helps :)
Christian Geib
826 PointsThanks for the quick and most helpful response. That did the trick:-)
Christian Geib
826 PointsChristian Geib
826 PointsThanks for the quick, elaborate and illuminating response. That did the trick:-)