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

what is wrong with my python if and else code, link source that i controlled with

first_name = input("What is your first name? ")
print("Hello, ", first_name)
if first_name == "kevin":
    print(first_name, "you are ok.")
print("Have a great day {}!".format(first_name))
else:
  print("sorry")
  print(first_name," go away")

https://www.tutorialspoint.com/python3/python_if_else.htm

[MOD: added ```python formatting -cf]

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,468 Points

There is an indention error.

first_name = input("What is your first name? ")
print("Hello, ", first_name)
if first_name == "kevin":
    print(first_name, "you are ok.")
# The print below "closes" the if statement above due to not being indented
print("Have a great day {}!".format(first_name))
else:  # <-- becomes orphan else statement and syntax error
  print("sorry")
  print(first_name," go away")

Correctly indent the third print statement, and all should be well. Post back if you need more help. Good luck!!