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 trialAdrian Brenton
8,110 PointsHaving 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
admitted = None
if age >= 13:
admitted = True
else:
admitted = False
2 Answers
Connor Walker
17,985 PointsThe 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
5,675 PointsHey 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!