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 trialGilang Ilhami
12,045 PointsUsing format
I think i forgot something about .format() Anybody can help?
class Store:
open = 8
close = 18
hours = "We're open from {} to {}.".format(open, close)
3 Answers
Chris Freeman
Treehouse Moderator 68,454 PointsYou need to add the method hours
and not just create hours attribute.
Try starting with:
class Store:
open = 8
close = 18
def hours(self):
# TODO: define formatted string
# TODO: return string
[your code here]
Gilang Ilhami
12,045 PointsHey Chris, thanks for the tip
but i think i still don't understand, something like this?
class Store:
open = 9
close = 18
def hours(self):
hours = "We're open from {} to {}.".format(open, close)
return self.hours
Chris Freeman
Treehouse Moderator 68,454 PointsThat's extremely close. Remember, when a method is run, it is operating on an instance of the class. In order to access attributes of the instance they must be prefixed with the instance reference "self." So, within the method the attributes would be referred to as self.open
and self.close
.
Gilang Ilhami
12,045 PointsHey Chris, again thank you for your reply, But i still don't get the concept about it Is it suppose to be like this?
class Store:
open = 9
close = 18
def hours(self):
houres = "We're open from {} to {}".format(self.open, self.close)
return self.hours
Chris Freeman
Treehouse Moderator 68,454 PointsYou're almost there. There is a typo in "houres". Also the local variable hours doesn't need the "self." since it isn't an attribute.
Gilang Ilhami
12,045 PointsThank you very much Chris :)