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 trial

Python

Ashley Keeling
Ashley Keeling
11,476 Points

I am not sure what I need to do for this to work

I am not sure about the hyphen part

morse.py
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
Wade Williams
24,476 Points

We have some cleaning up to do.

  1. Remove super().__str__(pattern)
  2. We don't need to split our pattern variable it's already a list
  3. Need to create a data structure (list in our case) to hold our result
  4. Add a loop to go through each character in the pattern list
  5. We don't want to return "dot" or "dash" we just want to add it to our result list
  6. 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
Ashley Keeling
11,476 Points

thanks , I wasn't sure about how you did it , but now I do thanks