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 Write Better Python Cleaner Code Docstrings

Rabih Atallah
Rabih Atallah
3,405 Points

identation error

Please why I get the error message: indentation error def student

starter.py
class Treehouse:
      """Methods related to Treehouse and student.
      """
    def student(self, name):
    """Gives a pleasant message about the student."""
        return '{} is a great Treehouse student!'.format(name)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,464 Points

The indention of an individual block of code must be consistant. The indention is set by the first line of the block. In your code, the first block statement is the doc-string comment (6 spaces). The function student() is indented only 4 spaces. So either remove two space in front of the doc-string (preferred), or add two spaces in front of the student() function.

class Treehouse:
    """Methods related to Treehouse and student.  #<-- two leading spaces removed
    """   #<-- two leading spaces removed
    def student(self, name):
        """Gives a pleasant message about the student."""
        return '{} is a great Treehouse student!'.format(name)

Edit: fixed student() docstring indention

Rabih Atallah
Rabih Atallah
3,405 Points

Thank you for your help Chris! I did it the way you suggested it's still not working which is really strange!

Chris Freeman
Chris Freeman
Treehouse Moderator 67,464 Points

Right, I missed another indention error. I updated my answer above to fix the docstring indention for student(). The docstring needs to be indented the same as the return statement.

Rabih Atallah
Rabih Atallah
3,405 Points

Thank you Chris it worked!