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 trialDrew Bissonnette
309 PointsMethod Hours
Not sure what else I am missing. I am not clear on what it means I have to press keywords to .format(). I rewatched the video again, am I still missing a step?
class Store:
open = 9
close = 8
hours = We're open from 9 to 8
def hours(self):
return self.hours.upper()
2 Answers
AR Ehsan
7,912 PointsIf this was helpful, fell free to mark as best answer
class Store:
open = 6
close = 9
def hours(self):
return "We're open from " + str(self.open) + " to " + str(self.close) + "."
[MOD fixed formatting -cf]
Chris Freeman
Treehouse Moderator 68,454 PointsA few thing to clean up: hours
used as both string name and method name; String formatting incorrect. self.hours
refers to the method not the string. Here's the commented and updated code:
class Store:
open = 9
close = 8
string = "We're open from {} to {}." #<-- name collides with method. Missing quotes, period
def hours(self):
return self.string.format(self.open, self.close) #<-- include reference to class using 'self.'
Chris Freeman
Treehouse Moderator 68,454 PointsChris Freeman
Treehouse Moderator 68,454 PointsNice answer. In addition to posting a solution, it is also helpful for the OP to understand where their code could be improved.