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!

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

Method named 'hours' is supposed to use .format() to return "We're open from {} to {}"

The question: 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 don't understand what you want.. i rewatched all the previous videos and there was NOTHING mentioned about .format(). I have tried answering the question every way possible and got nothing

6 Answers

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,073 Points

The format() function is heavily used in Kenneth videos. You have to put those placeholders ({}) inside of the string, and then in the arguments of the format() function put what you want to appear inside of those placeholders.

class Store:
    open = 9
    close = 21

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

I hope that helps a little bit

I am still trying to understand why there is self.open, self,close.

Hi I am just wondering why is it self. open and self.close instead of just open and close?

I am also confused..Why is it not just open and close?

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

Jon Helmus
Jon Helmus
7,312 Points

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

return needs to have "()" so you can pass through the prompt

Ilia Galperin
Ilia Galperin
6,522 Points
class Store:
    open = 73
    close = 44

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