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 trialBenito Thompson
1,650 PointsWhy won't this work?
I know I can probably use the "-".join() and maybe an empty list that i fill with respective dashes and dots to solve this, but i was just wondering why this doesn't work.
class Letter:
def __init__(self, pattern=None):
self.pattern = pattern
def __str__(self):
string = ""
if self.pattern[0] == '.':
string += 'dot'
elif self.pattern[0] == '_':
string += 'dash'
for item in self.pattern[1:]:
if item == '.':
string += '-dot'
elif item == '_':
string += 'dash'
return string
class S(Letter):
def __init__(self):
pattern = ['.', '.', '.']
super().__init__(pattern)
1 Answer
Chris Freeman
Treehouse Moderator 68,454 PointsYou are very close. It looks like you are missing a hyphen in front of the "dash". Should be:
string += '-dash'