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 trialJay Stratton
3,713 PointsI'm having difficulty understanding this challenge
How can I assign a variable to be true if the variable is already assigned false?? if you cannot change the variable assigned, then how can I create an "if" statement that changes false to true without changing false?
admitted = None
age = 32
if age > 13:
3 Answers
jcorum
71,830 PointsLike this:
admitted = None
if age >= 13:
admitted = True
else:
admitted = False
You've highlighted the essential nature of variables: their value can change from time to time as a program runs. First admitted is None. Then, depending on the value of age, it will be set either to True or to False.
Fable Turas
9,405 PointsActually that 'else' block is not necessary in this scenario. Since 'admitted' starts with a value of None which is falsey by nature. You only need the 'if' portion of the block which changes 'admitted' to True only when 'age' passes the conditional test. If 'age' fails the conditional test, 'admitted' would still be equal to None which would evaluate as False in a conditional test set against it.
Jared Syrenne
948 Pointsadmitted = none if age >= 13: admitted = "true" else: admitted = ""