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

Jan Lundeen
Jan Lundeen
5,887 Points

On challenge task 2 of 2, after I took out my variable (age = 13), it passed. Doesn't the statement need this variable?

On challenge task 2 of 2 (OK, one more. Add an else to your if. In the else, set admitted to False), after I took out my variable (age = 13), it passed. Doesn't the statement need a variable?

Here's the code I used originally. I got this error message. Error - Bummer! Don't set the age variable, I'll do that for you.

Admitted = None age = 13 <--- I had to take this line to get the 2nd challenge to pass. if age >= 13: admitted = True else: admitted = False

When I erased the second line (setting the variable), it passed:

age = 13 <--- I had to take this line to get the 2nd challenge to pass.

Passing code:

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

Don't I need to set variables for everything used in the if and else statements?

Thanks,

Jan

Jan Lundeen
Jan Lundeen
5,887 Points

I seem to be having problems editing my question. It looks like the lines are not separated properly. I pressed "enter" but it didn't print separate lines. On my original code (after "Admitted = None"), the second line should be "age =13". The third line should be "if age >= 13:. The fourth line should be "admitted = True". The fifth line is "else:". The sixth line is "admitted = False".

I hope this helps!

Jan

1 Answer

andren
andren
28,558 Points

The error message that accompanied your original code holds a bit of a hint:

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

It is true that if you were to run your code in an independent clean Python environment, you would need to set the age variable yourself. But when you are doing challenges on Treehouse your code does not run in a completely clean environment, Treehouse has some code that loads before your code runs that is responsible for checking that your code functions as expected. And that code will occasionally include things like declaring variables and setting them to a specific value. Meaning that even if you don't set the age variable yourself the age variable will still exist, because the challenge checker code that runs your code created it. And in fact by declaring the variable yourself you are overriding the value the code checker sets for you, which causes it to not work properly.

When doing these challenges it is therefore somewhat important to only write the code you are directly asked to write. Adding any code that is not requested in the challenge text will often cause issues with the code checking of your solution. Even if you feel the code you added makes the program more complete and functional than the code the challenge asks for.

Jan Lundeen
Jan Lundeen
5,887 Points

Hi Andren,

I understand that. However, it's important to understand why as well as just getting through the challenges. I want to make sure I can code something in python in the real world. So in the real world, It sounds like you agree that you would need to have the variable for age.

I know that you did not design the program Treehouse uses. However, since the course is supposed to teach correct coding, this sounds like they need to clean up the environment. Or maybe they could provide a message telling a user what the program has done.

Thanks,

Jan

andren
andren
28,558 Points

Oh don't get me wrong I entirely agree that in a real world app that variable would be needed, and I don't disagree with your opinion on the code challenge system that Treehouse has developed.

I spend a decent amount of time hanging out in this forum helping people, so I know first-hand how many people end up having issues not because of an actual fault with their code, but because of an issue with the code checker itself. It is certainly not an insignificant number of people. In fact the exact issue you ran into (adding the age variable in this challenge) is something that has caused issues for a number of other students somewhat recently as well.

Jan Lundeen
Jan Lundeen
5,887 Points

Thanks for confirming that a variable is needed and helping me understand that it's due to a problem with the code checker. Do you know if Treehouse is aware of this problem with the code checker? Since so many students have been affected, it's not an isolated problem (or simply user error). If not, we should enter a defect report (I'm a quality assurance analyst, so I do this as a living). What do you think?

Thanks,

Jan