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 trialAshley Keeling
11,476 PointsI am not sure what I need to do for this to work
I am not sure about the hyphen part
class Letter:
def __init__(self, pattern=None):
self.pattern = pattern
def __str__(pattern):
super().__str__(pattern)
pattern.split(",")
if pattern =".":
return "dot"
if pattern = "_":
return "dash"
pattern.join("_2")
class S(Letter):
def __init__(self):
pattern = ['.', '.', '.']
super().__init__(pattern)
1 Answer
Wade Williams
24,476 PointsWe have some cleaning up to do.
- Remove super().__str__(pattern)
- We don't need to split our pattern variable it's already a list
- Need to create a data structure (list in our case) to hold our result
- Add a loop to go through each character in the pattern list
- We don't want to return "dot" or "dash" we just want to add it to our result list
- Return our result list joined by "-"
All together now
def __str__(self):
result = []
for char in self.pattern:
if char == ".":
result.append("dot")
elif char == "_":
result.append("dash")
return "-".join(result)
Ashley Keeling
11,476 PointsAshley Keeling
11,476 Pointsthanks , I wasn't sure about how you did it , but now I do thanks