Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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))

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))

2 Answers

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 28,992 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))