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

It shows invalid syntax while working in quiz

It shows invalid syntax. while working with quiz. where i'm going wrong

conditions.py
admitted = 2
age = 12;

if (amitted < age):
    print(admitted)
    else:
        print(age)

2 Answers

Hey srinath! I think you need to read the instructions again, but ill give you some hard pointers:

  • When making an "if" statement, dont put parenthesis around the condition.
  • You shouldent create the age variable yourself, it has already been created, so remove that.
  • You shouldent change the admitted variable, leave it equal to None.
  • You shouldent print anything in this challenge.
  • You shouldent check if admitted < age. You should check wether age is greater that or equal to 13. Use "<=" operator for that.
  • An else statement should go directly under the if, not indented.
if (Your condition): # Ignore parenthesis
    # Do something
else: # Dont indent this else statement
    # Do something else

Please write back if you need more help!

Blake Fleisher
Blake Fleisher
2,848 Points

There are a few issues going on here:

(1) You initialize the variable admitted, but then say admitted in the if statement. So that's a big typo! (2) It should still work with the semicolon, but it's not needed on not very pythonic. (3) Indentation matters in Python, so your else statement should be below the if.

Your code should look like this:

admitted = 2
age = 12

if admitted < age:
    print(admitted)
else:
    print(age)

Note that these are just syntactic issues with your code. I have no idea what the challenge is about.