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

SACHIN GUPTA
SACHIN GUPTA
918 Points

please let me know where I went wrong with the creation of method hours in method.py. Please help!

please let me know where I went wrong with the creation of method hours in method.py. Please help!

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

  def hours(open, close):
    str_open=str(open)
    str_close=str(close)
    return_text = "We're open from {} to {}.".format(str_open, str_close)
    return return_text

1 Answer

Brian Jones
Brian Jones
5,803 Points

Your first argument to a class method should be self, so in this case your hours() method would have 3 arguments: self, open, close.

However, open and close are already properties of your class. They probably shouldn’t be arguments to this hours method at all, and instead you should be referring to self.open and self.close in your method.