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

Alternate responses to different names arent printing

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 in the community! Me too!")
else:
    age = int(input("how old are you?    "))
    if age <= 6:
        print("wow you're {}! If you're confident with your reading already...".format(age))
    print("You should totally learn Python, {}!".format(first_name))
print(first_name, "is learning python")

Mod Edit: Fixed code formatting. See comment for how to make your code fancy and readable in your posts.

Did you save your work first? Can you format your code using markdown?

rydavim
rydavim
18,766 Points

You can format your code in posts by using some special markdown.

```python

Your code here!

```

This is especially useful for Python, where some errors may be related to white-space.

rydavim
rydavim
18,766 Points

Your code appears to be working as expected for me. Can you elaborate on the issues you're having?

2 Answers

Steven Parker
Steven Parker
210,425 Points

Because it is not indented, that last "print" will be done in all cases. It looks like it was only intended for the "else" case, and for that it needs to be indented.

If that's not your issue, please describe it in a bit more detail.

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 in the community! Me too!")
else:
    age = int(input("how old are you?    "))
    if age <= 6:
        print("wow you're {}! If you're confident with your reading already...".format(age))
        print("You should totally learn Python, {}!".format(first_name))
        print(first_name, "is learning python")

I'm not entirely sure what your intention is with your code... but it works perfectly! You must remember to indent your code properly or python won't be able to understand, with the last three 'print' functions they all need to be indented with the same spacing beneath the 'if' statement for these actions to be executed when the code runs.