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

2nd portion isn't passing

Maybe it's just because it's late and I'm tired, but I feel like I'm not even close to getting the second portion of this code to work... What am I missing?

method.py
class Store():
  open = '9'
  close = '12'
  def hours(self):
    hoursopen = []
    sentence = "We're open from {} to {}."
    hoursopen.append(sentence.format(**open, close))
    return self.hoursopen

3 Answers

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Carina.

In this case I would simply go with the return statement inside the method definition. All we need here is one line, the return line.

What do we want to return? "We're open from {} to {}" (string plus 2 placeholders) and adding a simple format method at the end of it. That should work fine.

Let me know I made it clear enough.

Vittorio

like metioned above just use the format method on the string and populate the placeholders with properties of the class.

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

Thank you. I knew my brain was making that way harder than it needed to be. Lol.