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 triallesley Banadzem
993 PointsDon't know what's actually wrong with my code for the morse challenge
def from_string (cls, string): stringList = string.split("-") lists = [] for char in stringList: if char == "dash": lists.append("_") elif char == "dot": lists.append(".")
return cls(lists)
class Letter:
def __init__(self, pattern=None):
self.pattern = pattern
def __iter__(self):
yield from self.pattern
def __str__(self):
output = []
for blip in self:
if blip == '.':
output.append('dot')
else:
output.append('dash')
return '-'.join(output)
@classmethod
def from_string (cls, string):
stringList = string.split("-")
lists = []
for char in stringList:
if char == "dash":
lists.append("_")
elif char == "dot":
lists.append(".")
return cls(lists)
class S(Letter):
def __init__(self):
pattern = ['.', '.', '.']
super().__init__(pattern)
1 Answer
Steven Parker
231,269 PointsYou're nearly there!
Just adjust your indent so that the "return" happens outside the loop, after the loop is finished.
Otherwise, you've got it!