Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics Types and Branching Comparisons

Khaled Khanfar
Khaled Khanfar
1,135 Points

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

Anthony Crespo
seal-mask
.a{fill-rule:evenodd;}techdegree
Anthony Crespo
Python Web Development Techdegree Student 12,961 Points

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.

Podrig Leoghain
Podrig Leoghain
5,094 Points

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

Khaled Khanfar
Khaled Khanfar
1,135 Points

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
Khaled Khanfar
Khaled Khanfar
1,135 Points

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