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

Karla Herdzik
Karla Herdzik
708 Points

This should work but it doesn't

In the quiz, I have typed:

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

However, the answer keeps coming back as "bummer, admitted isn't False". I thought maybe it was because, as directed, I had set age to 13, per directions in step 1. So I changed my age to 12, which should have returned admitted as False, but then I get the error stating step 1 is no longer passing.

When I do the following in the workspace, the logic all works out. What am I doing wrong?

age = 13
if age >=13:
... admitted = True
... else:
... if age < 13:
... admitted = False
...

admitted
True

KeyboardInterrupt
age = 12
if age >=13:
... admitted = True
... else:
... if age <13:
... admitted = False
...
admitted
False

conditions.py
age = 13
if age >= 13:
  admitted = True
else: 
  if age <= 13:
    admitted = False 
Karla Herdzik
Karla Herdzik
708 Points

Also, yes, I see the typo in the code attached to this post...if age <=13: won't work to give me false...

However, when I simply type if age <13: it still doesn't work either.

1 Answer

Hi Karla,

Firstly, the question says that the age variable is set outside of the challenge. So delete your code that resets the value of age as this will override the tests and make your code fail. The challenge test will run your code twice and check it works by setting age to be, say, 10 and then 15. Your code then overrides that so the tests don't work as they should so they fail your code. If the code is run with age being set to 10 by the challenge, your code sets admitted to True. Try this instead:

code.py
admitted = None
if age >= 13:
  admitted = True

Next, you have tested age in your else block; delete that. The if condition is mutually exclusive, you're either 13+, or you're not; there's no need to test that again; if the original outcome isn't True, the only other option is False in this scenario:

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

I hope that makes sense.

Steve.

Karla Herdzik
Karla Herdzik
708 Points

Ah, ok I see it now. I misunderstood the initial instructions, and thought it actually wanted ME to set the age. Now I understand why it didn't work. Thanks much for the quick response!

No problem - glad you got it sorted. :smile:

Steve.