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

Salma Al
Salma Al
426 Points

can someone solve this for me please? i need to see an example, the problem is poorly worded.

I don't understand my syntax error; i tried this on my workspace and it worked.

conditions.py
admitted = None
if age > 13:
    print("True")
    else:
         print("False")

2 Answers

andren
andren
28,558 Points

There are two issues with your code, the first which is producing the syntax error is that the else statement is indented to be inside of the if statement, in Python how you indent your code is matters a lot. Else statements are meant to be intended to the same level as their accompanying if statement.

The second issue is that the task ask you specifically to "make an if condition that sets admitted to True if age is 13 or more." notice that there is no mention of printing anything, which is what you are doing in your code. They want you to change the value of the admitted variable.

Here is the solution were I fix those two issues:

admitted = None
if age > 13:
    admitted = True # Set admitted to True
else: # Make the else statement be on the level (indentation) as the if statement.
    admitted = False # Set admitted to False

I also added comments pointing out the parts of your code that I changed.

Simon Coates
Simon Coates
28,694 Points

try:

admitted = None
if age > 13:
    admitted = True;
else:
    admitted= False;
Salma Al
Salma Al
426 Points

thank you!