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 Python Basics (2015) Python for Beginners Syntax and Style

i wrote the codes but is says invalid syntax

i wrote the codes but is says invalid syntax
def answer_the_phone(): greeting = "Hello, treehouse?" print(greeting)

__ROLLER__ Angel
__ROLLER__ Angel
25,606 Points
def answer_the_phone():
    greeting = "Hi Treehouse!"
    print(greeting)

Pay extra attention to the indentation as it is a huge part of Python syntax. Be sure to check out this style guide

2 Answers

Did you remember to indent (add four spaces to the beginning) of the code that is part of the function?

Python will cause an error if you don't indent, because Python won't know that part of your code is part of the function.

To fix this, add 4 spaces to the beginning of the lines that are part of the answer_the_phone function, like this:

def answer_the_phone():
    greeting = "Hi Treehouse"
    print(greeting)

Good luck! ~alex

__ROLLER__ Angel
__ROLLER__ Angel
25,606 Points
def answer_the_phone():
    greeting = "Hi Treehouse!"
    print(greeting)

Pay extra attention to the indentation as it is a huge part of Python syntax. Be sure to check out this style guide