Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Logic in Python Conditional Value

Why is this code not accepted?

Why is this code not accepted for the challenge? It works fine on my python box.

admitted = None age = 15

if age > 12: admitted = True print(admitted) else: admitted = False print(admitted)

conditions.py
admitted = None
age = 15

if age  > 12: 
    admitted = True
    print(admitted)
else:
    admitted = False
    print(admitted)

1 Answer

andren
andren
28,538 Points

The reason is stated pretty clearly by the error message your code produces:

Don't set the age variable, I'll do that for you.

For this challenge the age variable is set by the code checker itself, you are not meant to define a value for it yourself. Doing so overrides the value the code checker uses which screws up it's ability to verify that your code actually functions correctly.

If you remove the age variable declaration like this:

admitted = None

if age  > 12: 
    admitted = True
    print(admitted)
else:
    admitted = False
    print(admitted)

Then your code works.