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 trialKhaled Khanfar
1,135 PointsI'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
Python Web Development Techdegree Student 12,973 PointsHi! 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
5,094 PointsAnthony is right. Remember, in Python indentation is your friend and your enemy ;)
Khaled Khanfar
1,135 PointsfirstName = 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
1,135 PointsThanks 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