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

Maciej Walczak
Maciej Walczak
5,042 Points

Create a class with a method.

Hello everyone, i'm having some trouble with this one. It works in workspaces, but not it the code challenge. Doeas anyone have any idea what i'm doing wrong?

method.py
class Store(object):
  open = 9
  close = 22

  def hours(self, open, close):
    return("We're open from {} to {}.".format(open, close))

1 Answer

Haider Ali
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Haider Ali
Python Development Techdegree Graduate 24,728 Points

Hi there Maciej, I have taken a look at you code and have found where you went wrong. When defining the hours method, the only argument that needs to be passed in is self. Then if you wanted to use the attribute e.g. open, you would write self.open instead. Here is what your code should look like:

class Store(object):
  open = 9
  close = 22

  def hours(self):
    return("We're open from {} to {}.".format(self.open, self.close))