Python Python Basics Logic in Python Conditional Value

Adrian Brenton
Adrian Brenton
7,049 Points

Having trouble with an 'if else' statement in Python Basics challenge

Hi, after having added the if statement in the task requesting this, on the Python basics course, the next task asks me to add an 'else' statement, and in it, to set 'admitted' to False

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

the challenge task then tells me that I've made a mistake when I check my work, and I can't seem to figure this out - please could someone advise me - am I making a mistake in my code?

Many Thanks

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

2 Answers

Connor Walker
Connor Walker
9,315 Points

The code that you have written is correct, it is just formatted wrong. The else needs to be indented the same amount as the if is, like this:

admitted = None
if age >= 13:
    admitted = True
else: 
    admitted = False
AJ Salmon
PRO
AJ Salmon
Pro Student 4,599 Points

Hey Adrian! The else block needs to be indented to the same column as the if. This is because the else happens when the if isn't truthy, so it needs to have the same level of indentation!