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 trialSteve Hunter
57,712 PointsMorse code challenge - can't solve it!
Afternoon all,
I've been staring at this for a while now and have browsed other solutions within the Community pages but can't see what I've done wrong here.
I think continuing to stare at the code is unlikely to produce a different result so I could do with some help, please!
Thanks,
Steve.
class Letter:
def __init__(self, pattern=None):
self.pattern = pattern
def ___str___(self):
output = []
for c in self.pattern:
if c == '.':
output.append('dot')
elif c == '_':
output.append('dash')
return "-".join(output)
class S(Letter):
def __init__(self):
pattern = ['.', '.', '.']
super().__init__(pattern)
2 Answers
Steven Parker
231,261 PointsYour code is fine.
You just have the wrong name for your method. You have "___str___
" (with 6 underscores), but the name should be "__str__
" (with 4 underscores).
Steve Hunter
57,712 PointsThanks Steven,
That's very odd, though. In the IDE, there's two underscores each side so there must be some weird copy/paste issue that I created.
Thanks again - that'll give me something more interesting to stare at today!
Steve.
Thomas Beaudry
29,084 PointsDid it work OK Steve Hunter, I am currently on this also? Thank you :)
Steve Hunter
57,712 PointsYep - all worked fine.
D Elis
13,571 PointsHey Steve.. did you find a solution to this challenge? I tried writing the same code you have above but with double underscores but my code still isn't passing
Steven Parker
231,261 PointsWhen I checked his code the first time, I copied the above and pasted it directly into the challenge. And then after only changing the name, it passed.