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 Types and Branching Comparisons

I'm getting elif syntax error anyone can help with this !

firstName = input("Please enter your first name !")

if firstName == "Khaled": print("Welcome Khaled to your Python class") elif firstName == "John": print("You are in the wrong Class")

    else:
        age == int(input("Please enter your age"))
        if age < 6:
            print("Wow you are still {} , firstName you should learn how to read darling.form(age)")

..........................................................................................................

                File "/home/main.py", line 13                                                                                                         
elif firstName == "John":                                                                                                           
   ^                                                                                                                                

SyntaxError: invalid syntax

4 Answers

Hi! It may happen cause you indented elif and else but I'm not sure if it was just an error when you copied and pasted your code. I unindented them and actually got a completely different error and it was in the else block.

firstName = input("Please enter your first name !")

if firstName == "Khaled":
    print("Welcome Khaled to your Python class")
elif firstName == "John":
    print("You are in the wrong Class")

else:
    age = int(input("Please enter your age"))  # here you used '==' instead of '='
    if age < 6:
        # In this next lane the function that replace the {} by the age value is actually called 'format()'
        # And you need to call it after the string and not inside of it.
        print("Wow you are still {} , firstName you should learn how to read darling".format(age))

Now your code should run correctly.

Anthony is right. Remember, in Python indentation is your friend and your enemy ;)

firstName = input("Please enter your first name !")

        if firstName == "Khaled":
            print("Welcome Khaled to your Python class")
          elif firstName == "John":
            print("You are in the wrong Class")

          else:
            age == int(input("Please enter your age"))
            if age < 6:
              print("Wow you are still {} , firstName you should learn how to read darling.form(age)")


       # Here is the code hope this time will appear good

Thanks Anthony Thanks guys for taking time to answer my question I'm still a beginner and now I realized something I should take care of in future while I'm writing my code