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 If, Else and Elif

Python: If, Else and Elif (Is there something wrong with my code?)

File "/home/treehouse/workspace/hello.py", line 5
elif first_name == "Maximliane":
^
SyntaxError: invalid syntax

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

1 Answer

Asher Orr
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Asher Orr
Python Development Techdegree Graduate 9,409 Points

Hi Chance! The conditional branching in your code- starting at line 5, on the elif statement- isn't correct.

Your elif and else statements should be indented at the same level as your if statement. Like this:

first_name = input("What is your name?:  ")
print("Hello,",first_name)
if first_name == "Chance":
    print(first_name, "is learning python")
elif first_name == "Maximliane":
    #printstatement
#and so on.

Head to the 9:38 mark in the video. Look at how Craig has his if/elif/else block structured. Change your code accordingly, and it will run properly.

Let me know if you have any questions. I hope this helps!