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

Gurutej Battaram
Gurutej Battaram
2,224 Points

Why won't the assignment in else block be done?

I have written a simple if-else condition for the challenge task, but it keeps returning the same error: "Bummer! 'admitted' is not False. I tried the exact same code in the console and it works fine. Please help me complete the challenge.

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

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

False and True are key words in Python. They should not be quoted unless you wish to create strings. So when it says admitted is not False it means it is not equal to the built in value. Remove the quotes.

Gurutej Battaram
Gurutej Battaram
2,224 Points

Wow! Thank you Chris. Got it done!! One doubt though. I get that the challenge wouldn't complete because 'admitted' couldn't be assigned False because of the quotes. But how did it work for True? Because that was the first task of the challenge, to assign 'admitted' the value of True and it worked with the quotes.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

The grader runs your code with various values for age to test the branches in the code flow.

When testing for True the grader may use the "truthiness" of admitted. When set to a string, admitted is "truthy".

Python 3.3.0 (default, Nov 26 2015, 16:04:52) 
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on unknown
Type "help", "copyright", "credits" or "license" for more information.
>>> 'string' == True
False
>>> if True:
...     print("is truthy")
... 
is truthy
>>> if 'True string':
...     print("is truthy")
... 
is truthy
Gurutej Battaram
Gurutej Battaram
2,224 Points

I get it now. Thanks a bunch !!