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

Only else statement is printing, even when I use different names.

Hi! Even though I believe I have indented properly and have compared my code to Craig's, I'm still only getting my "else" statement. This happens even when I input first_name objects that should print other statements. What might be wrong?

Whoopsie didn't know how to attach my code! Here it is:

first_name = input("What is your first name?  ") 
print("Hello,", first_name)
if first_name == "Bella":
    print(first_name, "is learning Python")
elif first_name == "Creighton":
    print("is learning law. So is Miles!") 
else: 
       print("You should totally learn Python, {}!".format(first_name))
print("Have a great day {}!".format(first_name))

Then, I am getting back this:

treehouse:~/workspace$ python hello.py                                                                         
  File "/home/treehouse/workspace/hello.py", line 5                                                            
    elif first_name == "Creighton"                                                                             
                                  ^                                                                            
SyntaxError: invalid syntax                                                                                    
treehouse:~/workspace$ python hello.py                                                                         
What is your first name?  Creighton                                                                            
Hello, Creighton                                                                                               
You should totally learn Python, Creighton !                                                                   
Have a great day Creighton !                                                                                   
treehouse:~/workspace$ python hello.py                                                                         
What is your first name?  Bella                                                                                
Hello, Bella                                                                                                   
You should totally learn Python, Bella !                                                                       
Have a great day Bella !                                                                                       
treehouse:~/workspace$                                                                                         

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

Hey Isabella Elyse Letson Ettin, a clue can be found in your output text.

The text shows β€œYou should totally learn Python, Creighton !”, but the code has:

"You should totally learn Python, {}!"

Notice there isn’t any space between the format placeholder and the exclamation point but a space is being printed in the output.

Perhaps you are entering an extra space during typing responses?

One workaround would be to replace the absolute match with a first_name.startswith() statement.

Post back if you need more help. Good luck!!!

Hi Chris,

Thank you for your help! This turned out the be the problem!