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

sandhya sivasankaran
sandhya sivasankaran
1,711 Points

If else challenge

I was asked to set admitted to true if age >= 13 else false, i wrote the below code, what is wrong with it? its not passing for some reason

admitted = None if age >= 13: admitted = True else: admitted = False

conditions.py
admitted = None
if age >= 13:
    admitted = True
    else: 
        admitted = False

3 Answers

Antonio De Rose
Antonio De Rose
20,885 Points
admitted = None #this is redundant, cause you can save it on the fly
if age >= 13:
    admitted = True
    else: #you have to have the else, aligned with the if, when it comes to indentation in python
        admitted = False #this will also have to follow, accordingly.
Luis Miguel Hernandez
Luis Miguel Hernandez
4,266 Points

Remember that the python code should always be indented, like this:

admitted = None #This line is not necesary

if age >= 13:
    admitted = True
else: 
    admitted = False
sandhya sivasankaran
sandhya sivasankaran
1,711 Points

Yes it was the indentation. Thank you very much for helping.