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

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