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

Now, add a method named hours that returns "We're open from {} to {}.". Replace the first placeholder with the open

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.

method.py
class Store:
    open = 9
    close = 5

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

1 Answer

Nathan Tallack
Nathan Tallack
22,160 Points

You were very close!

Two things. First, your W in We're is not capital. Not sure if it would care, but the challenge has it quoted as a capital. Second you need to refer to self when using your class properties inside it's methods.

Your code with these changes would look like this.

class Store:
    open = 9
    close = 5

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

Keep up the great work! :)

thank you sir, it worked

mohammed abdi abdulahi warsame
mohammed abdi abdulahi warsame
4,926 Points

1 = cant i just do like this instead of doing it in youe way?: class Store: open = 9 close = 5

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

2= and let us say we used your method way did you used .self in (self.open, self.close) ?