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) Logic in Python Conditional Value

I am having a problem with the challenge. It gives me a syntax error on line 1, but line 1 was part of original code

admitted = None if age >= 13 then admitted = True

conditions.py
admitted = None
if age >= 13 then
    admitted = True

3 Answers

Samuel Ferree
Samuel Ferree
31,722 Points

Not sure why it says the error is on line 1, but python uses a colon (:) instead of 'then' after if statements

admitted = None
if age >= 13: # use : not 'then'
  admitted = True

While it does say line 1 when I try it also, the actual issue is on line 2 - python doesn't use the if-then format, but rather a colon to end the 'if' line. If you take out the 'then' and add a colon (:), it should pass. Like this:

admitted = None
if age >= 13:
    admitted = True
Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

For those wondering about why the compiler stated line #1 ...
In programming, pretty much every time you have a syntax error, the compiler will indicate the previous line, but this isn't really what the compiler is doing. When is says line #1, it is saying that that was as far as it could go before the code 'broke'. The compiler could not compile line #2 because of the error, so, it its 'world' line #2 doesn't really exist, so it thinks the problem happened after line one compiled.

In short, whenever you get a line number "showing" a problem, always look at the line (or even lines) after the line number given.
I hope this helps to clarify why it was "Line 1" and not Line 2 that the compiler threw out.

Keep Coding :) :dizzy: