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

Jay Stratton
Jay Stratton
3,713 Points

I'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

Like this:

admitted = None
if age >= 13:
  admitted = True
  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
Fable Turas
9,405 Points

Actually 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
Jared Syrenne
948 Points

admitted = none if age >= 13: admitted = "true" else: admitted = ""