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 Object-Oriented Python (retired) Objects Create a Class with a Method

Zack Parr
Zack Parr
4,091 Points

I have no idea how to create a method for this object

I think I'm doing it right, but it's not showing up right, and Treehouse is not giving me a hint. Is it because I'm using 'self' as an argument? am I doing the .format() thing wrong?

method.py
class Store(object):
  open = 9
  close = 7
  def hours(self):
    return "We're open from {} to {}.".format(open, close)

1 Answer

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Zack.

I think you are pretty close, but I see something is missing in the last set of parenthesis.

open and close are attributes of the Store class, so if you want to access them in the hours method (that takes self as argument), you will need to specify that. So for instance: self.open

Same thing for the close attribute.

I hope I made it clear.

Vitto