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 trialEthan Pyles
2,710 PointsBummer: Try again! I ran this code in the workspace and got a SyntaxError
I got the error pointing at the beginning of code.append(item) = 'dash' of the elif
class Letter:
code = []
def __init__(self, pattern=None):
self.pattern = pattern
def __str__(self):
for item in self:
if item == '.':
code.append(item) = 'dot'
elif item == '_':
code.append(item) = 'dash'
return ('-'.join(code))
class S(Letter):
def __init__(self):
pattern = ['.', '.', '.']
super().__init__(pattern)
1 Answer
Scott Bailey
13,190 Pointsdef __str__(self):
morse_code = []
for item in self.pattern:
if item == ".":
morse_code.append("dot")
elif item == "_":
morse_code.append("dash")
else:
pass
return "-".join(morse_code)
You need to loop through the instance of the pattern not 'self'.
for item in self.pattern:
Other than that everything else looks good!
I hope this helps you out!
(An issue I have with the challenges is that when you edit code and resubmit it will still tell you it's wrong. If you have this issue delete everything refresh the page and paste it back in!)