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

David Kan
David Kan
4,058 Points

object oriented challenge 2 of 2 objects

Now, add a method named hours that returns "We're open from {} to {}.". Replace the first placeholder with the open time and the second with the close time. Remember you need to pass keywords to .format() if your placeholders have names.

i have this so far

class Store: open = 9 close = 9

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

2 Answers

Ron McCranie
Ron McCranie
7,837 Points

First thing is that you're passing the class name to the hours method, if this is a method of the class itself then you need to reference it differently.

Second, it looks like you're not passing any values to the 'format' method. You should pass the 2 values in the format method separated by a comma.

Saghir Hussain
Saghir Hussain
8,765 Points

The code below doesn't work and I have no idea why. Its saying that task 1 is no longer passing. Any ideas anyone? class Store: open = 9 close = 17

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

I did it this way:

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