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 trialCole Cramer
587 PointsMethod 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
21,074 PointsThe 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
Jude Molloy
7,470 PointsHi I am just wondering why is it self. open and self.close instead of just open and close?
Navalkrushna Allurwar
3,557 PointsI am also confused..Why is it not just open and close?
Wesley Kasambira
5,932 Pointsclass Store: open = 8 close = 17 def hours(self): hours = "We're open from {} to {}.".format(self.open, self.close) return hours
Jon Helmus
7,312 Pointsdef 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
6,522 Pointsclass Store:
open = 73
close = 44
def hours(self):
frase = "We're open from {} to {}."
return frase.format(self.open, self.close)
Ankit Pansari
6,208 PointsAnkit Pansari
6,208 PointsI am still trying to understand why there is self.open, self,close.