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

Confused how to write the code for this...

I am not sure if the code is correct. I keep getting an error for this and am not sure if I have it written correctly. I think I have the write idea but am a bit stuck.

conditions.py
admitted = None
if admitted>13:
    print("True")

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

You're very close. The challenge want you to assign the value to admitted after comparing the value of age Is greater than or equal to 13:

admitted = None
if age >= 13:
    admitted = True

Thanks Chris,

If I wanted to set admitted to false with an else, would you have to rewrite the if statement to say less than or equal to? I keep getting "It looks like task 1 is no longer passing." You know the videos make a lot of sense, and I seem to be able to type the code out fine in workspaces, but some of the challenges are a bit confusing or slightly different than the videos. Is it just a matter of lots of practice, or do you recommend a certain way of thinking about these questions? Thanks and really enjoying the coursework.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,426 Points

When the challenge says "Task one is no longer passing, it usually means there's a syntax error. Did you remember the colon at the end of the else. Also check you indentation.

The else never has a conditional statement. The conditional for the else is the logical complement of the if or elifconditionals.

The full solution should like similar to this

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

The language of the challenges is meant to use realistic terminology. Sometimes the descriptions aren't obvious but you learn as you go. It will become easier as you progress.

Always ask in the forum if you are stuck or unsure. That's what we're here!

Chris Freeman
Chris Freeman
Treehouse Moderator 68,426 Points

Follow up. The challenge could have been written to accept these alternatives. But these both have more overhead.

Explicitly checking the else condition is slower. It also causes code reviewers more time to be sure the second condition is correct.

admitted = None
if age >= 13:
    admitted = True
elif age < 13:
    admitted = False

As two independent if statements, both have to evaluate regardless of the age value

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