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 Write Better Python Cleaner Code Function and Class Whitespace

cleaner code

how do i solve this guys?

starter.py
def first_function(arg1):
    return 'arg1 is {}'.format(arg1)


def second_function(arg1):
    return 'arg1 is {}'.format(arg1)


class MyClass:

    args = [1, 2, 3]

    def class_func(self):
        return self.args

2 Answers

It's looking for:

  • 2 new lines between the functions
  • 2 lines between the function definitions and the class definition
  • 1 new line between the args declaration and class_func
  • 1 New line at the end of the file
def first_function(arg1):
    return 'arg1 is {}'.format(arg1)


def second_function(arg1):
    return 'arg1 is {}'.format(arg1)


class MyClass:
    args = [1, 2, 3]

    def class_func(self):
        return self.args

OK...But how do you add a new line on the file?

Just hit return after the last line of MyClass and be sure to remove any whitespace from that line.

Thanks a lot Geoff it worked out

antonio butler
antonio butler
2,514 Points

sorry quick question, how do you guys add, subtract white spaces and how do you create new lines?

i ask because when i originally did this problem i just went to the end above where i wanted to add space and hit "enter" there. this cause my challenge to increase my "errors" instead of decreasing them. after some trial and error i went to the beginning of the line right after where i wanted to add my space and hit enter there. this caused my code to be viewed as correct but i do not understand the difference between what i "was" doing and what i "eventually" did.

even if you dont know exactly why the two ways were different just knowing how everyone add/subtracts lines would be appreciated, technically i do not know how Kenneth added/subtracted the white space so smoothly in his video with 1 button press so knowing that would be awesome.

P.S. i apologize for the long question. ill try to keep them short and sweet in the future.