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 Comparisons

elif

why is my code not working

first_name = input("What is your name") 
print("Hello,", first_name)
if first_name == "mimi":
    print(first_name, "is learning python")
    elif first_name == "wale":
        print(first_name, "is learning with a fellow")
        else:
            age =input("How old are you")

            print("You should totaly learn python, {}!".format(first_name))
            print("have a good day{}".format(first_name))

3 Answers

Ryan Markey
seal-mask
.a{fill-rule:evenodd;}techdegree
Ryan Markey
Front End Web Development Techdegree Student 12,565 Points

Your code works perfectly Kevin, the issue you are having is indentation and formatting.

You have:

if first_name == "mimi":
    print(first_name, "is learning python")
    elif first_name == "wale":
        print(first_name, "is learning with a fellow")

When it should be:

if first_name == "mimi":
    print(first_name, "is learning python")
elif first_name == "wale":
    print(first_name, "is learning with a fellow")

Remember that python uses indentation and spaces in place of opening and closing curly braces '{ }', code must be properly formatted to work as intended.

Try pasting this inside your workspace and try it out.

first_name = input("What is your name?  ") 
print("Hello,", first_name)
if first_name == "mimi":
    print(first_name, "is learning python")
elif first_name == "wale":
    print(first_name, "is learning with a fellow")
else:
    age =input("How old are you")

print("You should totaly learn python, {}!".format(first_name))
print("have a good day{} ".format(first_name))
Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 37,799 Points

I think it might just be formatting. Your if, elif and else need to line up. The prints need to not be indented or will only run if the else clause is executed. Unless the last prints are only suppose to print if the else is run then leave them indented. Let me know if you still need help.

first_name = input("What is your name") 
print("Hello,", first_name)
if first_name == "mimi":
    print(first_name, "is learning python")
elif first_name == "wale":
    print(first_name, "is learning with a fellow")
else:
    age =input("How old are you")

print("You should totaly learn python, {}!".format(first_name))
print("have a good day{}".format(first_name))

print("Hello,", first_name) It should be print("Hello", first_name) Yo need to remove ,

first_name = input("What is your name") print("Hello", first_name) if first_name == "mimi": print(first_name, "is learning python") elif first_name == "wale": print(first_name, "is learning with a fellow") else: age =input("How old are you")

print("You should totaly learn python, {}!".format(first_name)) print("have a good day{}".format(first_name))