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 trialJason Lysinger
1,365 PointsMethod not working in challenge but seems to work fine in console.
Here is the challenge 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.
Here is my code:
class Store:
open = 9
close = 10
def hours(open, close):
hour = "We're open from {open} to {close}".format(open=open, close=close)
return hour
I try it in a Python console and it gives me the expected output:
We're open from 9 to 10
But I can't get it to work in the challenge and it gives me no hints on how to fix it. Just a "Bummer! Try again!"
4 Answers
Kenneth Love
Treehouse Guest TeacherYour hours
method doesn't have self
as the first (and, really, only) argument and your open
and close
variables, inside, should be self.open
and self.close
. Other than that, looks good.
beven nyamande
9,575 Pointsmine failed to run initially due to indendation
beven nyamande
9,575 Pointsmine failed to run initially due to indendation
MUZ140082 mucheni
1,244 Pointsthank you Kenneth the method worked
Jason Lysinger
1,365 PointsJason Lysinger
1,365 PointsThank you for that, it does make sense now.
That worked to complete the challenge, but I am sure I could just remove the variable and just return it like this?
return "We're open from {} to {}.".format(self.open, self.close)
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherJason Lysinger you definitely could.