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 trialLuis Semprun
Courses Plus Student 4,393 PointsRight Output for the code challenge But it says its wrong?
I am getting the output "dot-dot-dot".
But I can not complete this challenge because I am getting everytime the following error:
Bummer: Didn't get the right string output. Got: dot-dot-dot for S()
Tried with two different def str(self) methods:
- def str(self):
string = ""
counter = 0
for m in self.pattern:
if m == ".":
string += "dot"
if m == "_":
string += "dash"
if counter != (len(self.pattern)-1):
string += "-"
counter += 1
return string
- def str(self): return str(self.pattern).replace('.','dot').replace(', ','-').replace('[','').replace(']','').replace('\'','')
class Letter:
def __init__(self, pattern=None):
self.pattern = pattern
class S(Letter):
def __init__(self):
pattern = ['.','.','.']
super().__init__(pattern)
def __str__(self):
return str(self.pattern).replace('.','dot').replace(', ','-').replace('[','').replace(']','').replace('\'','')
1 Answer
Steven Parker
231,248 PointsYou're close, but:
- the method was added to "S", but the instructions say "to add a
__str__
method to the Letter class ..." - they also say that the method should return "dash" for every "_" (underscore)
The "Bummer" may be a bit misleading since the second problem is detected when testing letters other than "S".