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 Smith
8,668 PointsGetting bummer
Not sure where i went wrong, any ideas?
class Letter:
def __init__(self, pattern=None):
self.pattern = pattern
def __str__(self, pattern=None):
self.pattern = pattern
code = []
translate = ""
for morse in pattern:
if morse == ".":
code.append("dot")
elif morse == "_":
code.append("dash")
for symbol in code:
translate.join("-")
return translate
class S(Letter):
def __init__(self):
pattern = ['.', '.', '.']
super().__init__(pattern)
1 Answer
Cheo R
37,150 PointsYou're close. Because you're printing a string representation of the pattern, you don't need to pass pattern in the string method and subsequently you can remove self.pattern because it's accessible from __init__.
In the for loop, you can access the pattern, using self.pattern.
You can get rid of your last for loop (an translate variable above) because:
- your code variable is a list of strings (dot, dashes, ect)
- the join method works on lists.
So all you would have to do is return the result of calling join (and what to join with) on your variable *code).
You're on the right track.