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

Dennis Moriarity
PLUS
Dennis Moriarity
Courses Plus Student 940 Points

Not 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")

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

3 Answers

Dennis Moriarity
PLUS
Dennis Moriarity
Courses Plus Student 940 Points

Hi 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

Ah okay,

So if it helps, all an if statement does is cause a branch in the run of your program. so in this example:

name = "Bob"
name = "Susan"
name = "Jeff"

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:

name = "Bob"
if name == "Bob":
    name = "Susan"
else:
    name = "Jeff"
name = "Jane"

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 :)

Hi 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
Rajan Thapa
633 Points

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