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

why my code shows error i have write all correct.

first_name = input(" what is your name? ") print("hello",first_name) if first_name == "craig": print(first_name, "is learning python") else first_name == "max": print(first_name, " is learning with fellow students in the community! Me too") elif: print("you should totally learn python, {}!".format(first_name)) print("Have a great day {}".format(first_name))

could you please format your code using the Markdown Cheatsheet https://teamtreehouse.com/community/cheatsheet I have no idea about your indentation.

1 Answer

Hi there! I see your else-statement comes before the elif-statement, and you haven't specified what the elif-statement should look for. With an else-statement that is not necessary, since it handles all the other things that you haven't told your if- and elif-statements to look for. See below what I mean. This code works well on my end.

first_name = input(" what is your name? ")
print("hello",first_name) 
if first_name == "craig": 
    print(first_name, "is learning python") 
elif first_name == "max": 
    print(first_name, " is learning with fellow students in the community! Me too") 
else: 
    print("you should totally learn python, {}!".format(first_name)) 
    print("Have a great day {}".format(first_name))