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 If This Then That

Lisa Ess
Lisa Ess
7,193 Points

When I try to use the "if not age" statement, I keep getting syntax errors. Halp?

I have tried to reproduce this just like the video and just get errors over and over again, pointing to the "if" part of the statement. Confuzzled.

5 Answers

Sebastian Sõeruer
Sebastian Sõeruer
12,353 Points

... print("You're old") <- you have 5 spaces in here, but it needs to be 4.

Hey Lisa,

There is an issue with the indentation of the print line. Should look like this

age = 34 * 365
if age > 10000:
    print("You're old")

Kenneth didn't mention about the indentation for "if" and "else" but I found the solution anyway (feel like I grow, yay!). Thank you Omar Richardson. If should not have any indentation but the workspace in the quiz always give us an indentation automatically. That's why it has syntax error. Thank you!

Lisa Ess
Lisa Ess
7,193 Points

Hrm. Okay. I was following the lesson and typed exactly what the lesson said.

>>> age = 34 * 365                                                                              
>>> if age > 10000:                                                                             
...     print("You're old")                                                                     
... if not age >20000:                                                                          
  File "<stdin>", line 3                                                                        
    if not age >20000:                                                                          
     ^                                                                                          
SyntaxError: invalid syntax
Nitram Sinned
Nitram Sinned
7,723 Points

It looks like you're missing the elif (if I'm reading this right);

age = 34 * 365
if age > 10000: ... print("You're old") ... elif not age >20000: ... print("You're young") ... You're old