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 trialMilagros Roman
1,228 Pointsthis gives me an error even if this works very well on the workplace
class Store: open = 9 close = 5
def hours(self): print("we are open from {} to {}".format(self.open, self.close))
tienda = Store() tienda.hours()
with this code on my workplace, I get : we are open from 9 to 5" as it is expected but on your challenge workplace it doesn't work :-9 loosing time..
class Store:
open = 9
close = 5
def hours(self):
print("we are open from {} to {}".format(self.open, self.close))
tienda = Store()
tienda.hours()
5 Answers
Dan Johnson
40,533 Pointshours needs to return a string, not print one. Also make sure your format string exactly matches the the one in the description:
"We're open from {} to {}."
Everything else looks fine (though creating a Store
and calling hours is not required).
Milagros Roman
1,228 Pointsthank you Dan... yupi .. It was so easy the problem was the phrase!!!! And obviously the print
Mila
Rodrigue Loredon
1,338 PointsHi guys, can you tell me why self.open and self.close instead of just open and close.
Dan Johnson
40,533 PointsYou need self in order to associate the instance of the calling object with the instance variables. Without self they could get confused with variables local to the function.
Rodrigue Loredon
1,338 PointsDan, is the calling object the hours method ?
Dan Johnson
40,533 PointsIn the case of the code:
tienda = Store()
tienda.hours()
tienda is what is calling hours as it is an instance of the Store
class. So any use of self in this particular call will refer to tienda.
Rodrigue Loredon
1,338 PointsAwsome, very clear, thank you very much.