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

if else elif. not sure what am i doing wrong

first_name = input("What is your first name? ") print("Hello,", first_name) if first_name == "Craig": print(first_name, "is learning Python") elif first_name == "Maximiliane": print(first_name, "is learning with fellow students in the community! Me too!") else: print("You should totally learn Python, {}!".format(first_name)) print("Have a great day {}!".format(first_name))

treehouse:~/workspace$ python hello.py
File "hello.py", line 5
elif first_name == "Maximiliane":
^
SyntaxError: invalid syntax

1 Answer

Hey, Samuel. When posting code to the forum, it's important to keep formatting in mind. The easier the post is to read, the easier it is for the community to lend a hand. Here's a primer on post formatting: https://teamtreehouse.com/community/posting-code-to-the-forum

As far as your syntax error goes, it looks like you've indented your elif and else where you don't need to. Your if else block should look more like

if first_name == "Craig":
    print(first_name, "is learning Python")
elif first_name == "Maximiliane":
    print(first_name, "is learning with fellow students in the community! Me too!")
else:
    print("You should totally learn Python, {}!".format(first_name))

Give that a try, it should work.