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 trialIsaac John
7,516 PointsClass and method Test
class Store:
open = '9'
close = '4'
def hours(self):
string = "We're open from {} to {}."
return self.string.format(open,close)
I get the message "hours not defined" or "try again" i've tried typing the the opening hours like: open = 9, open = '9' i'm stuck i'm doing it just as in the video..i think
http://teamtreehouse.com/library/create-a-class-with-a-method
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi Isaac,
I checked the challenge and it doesn't seem to care whether you store the hours as integers or strings. Based on the instructions it looks like they should be stored as integers without quotes.
Your real issue is the return statement.
string
is a temporary local variable that you created to store the output string. It's not an attribute of the class so you wouldn't need to access it using self
On the other hand, open
and close
are attributes of the class and would need to be accessed using self
Isaac John
7,516 PointsIsaac John
7,516 Pointsthanks!!!
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsYou're welcome.
To save a line of code you could even skip the
my_string
variable and return the string directly.return "We're open from {} to {}.".format(self.open, self.close)