Python Python Basics Types and Branching If, Else and Elif

elif syntax error

Hi , while i was testing the code i face the error which says elif first_name == "arsham": SyntaxError = invalid syntax here is my code:

first_name = input("what is your firstname? ") print("hello" , first_name) if first_name == "Craig": print(first_name, "is learning python")
elif first_name == "arsham": print("you should learn python") else: print(first_name , "will start learning python")

4 Answers

Nils Kriedner
Nils Kriedner
23,087 Points

Hi Arsham,

I have just started learning Python as well, so I cannot explain why your version is actually not working...

I just know that if you use the .format function it works. And that is what is being used in that course:

So with format it would look like this and worked when I tried:

first_name = input("what is your firstname? ")
print("hello {}".format(first_name))
if first_name == "Craig":
    print("{} is learning python".format(first_name))
elif first_name == "arsham":
    print("you should learn python")
    print("{} will start learning python".format(first_name))

And surely someone else can point out why it does not work to use the concatenation as you did. Because I have no idea why and would be curious to know as well... :-)

Happy coding!


thanks for all of the replies guys, the problem was in indenting the else. i got it fixed.

Hi Arsham,

Are you sure you quit REPL? Type "exit()" and then try to run your code again.

Robin Versloot
Robin Versloot
7,325 Points

Try to print a variable then put a + and then the string.

Example: Print("welcome to Python" + first_name)