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 trialDennis Moriarity
Courses Plus Student 940 PointsNot sure what I am doing wrong
I run the same script in my workspace and it works but in this exercise it says It does not work.
admitted = None age = 13
if age >= 13:
... print("admitted = True")
admitted = None
age = 13
if age >= 13:
print("admitted = True")
3 Answers
Dennis Moriarity
Courses Plus Student 940 PointsHi Jon,
The question we were asked to solve is: I'm going to create a variable named age. I need you to make an if condition that sets admitted to True if age is 13 or more.
In the prior video there was nothing teaching us to change a value using a IF statement. Am I just reading the question wrong? If so, what is it that i am missing/ Thanks
Jon Mirow
9,864 PointsHi there!
I think you've left a debugging print statement in your code. At the moment you are printing the string
'admitted = True'
instead of setting the variable admitted to be the value True
Hope it helps :)
Rajan Thapa
633 Pointsadmitted = None if age >= 13: admitted = True
Jon Mirow
9,864 PointsJon Mirow
9,864 PointsAh okay,
So if it helps, all an if statement does is cause a branch in the run of your program. so in this example:
Will result in the name variable holding the string "Jeff" because python runs down the file from the top to the bottom. First it sets name to Bob, then Susan and finally Jeff.
When we use an if statement we can change the flow of the program:
Here Python starts at the top, and sets name to hold the string Bob, then it reaches the if and can go down one of two paths. If checks if the value of name is Bob, and then goes down the first path, setting name to Susan. The else doesn't run, and the program re-enters at name = "jane" so the name now changes from Susan to Jane.
The print function however takes whatever you give it and prints it in the termal outside of the code, it doesn't have any effect on your code.
Hope it helps :)