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

January Johnson
January Johnson
23,855 Points

Dont get it at all.

Completely lost here.

morse.py
class Letter:
    def __init__(self, pattern=None):
        self.pattern = pattern
    def __str__(self):
        self.s = s
        for p in self.pattern:
            s=s+"dot-"
        return s

class S(Letter):
    def __init__(self):
        pattern = ['.', '.', '.']
        super().__init__(pattern)
Tyler B
Tyler B
5,787 Points

Can you add some details into what/where in the code your lost and what you are or are not seeing that you expect?

1 Answer

Steven Parker
Steven Parker
230,231 Points

The sample letter "S" happens to contain only dots; but your method should work on letters with any pattern and handle dots, dashes, and combinations of both.

Also, when creating the local variable "s", don't put "self." in front of it. And you cannot assign it with itself while it is being created.

January Johnson
January Johnson
23,855 Points

This is my code. It returns this error: "Bummer: Didn't get the right string output. Got: dot-dot-dot for S()" I thought that was what he was asking for. Again, I'm completely lost here.

python
class Letter:
    def __init__(self, pattern=None):
        self.pattern = pattern
        self.code = []
        self.dash = "-"
    def __str__(self):
         if '.' or '-' in self.pattern:
            for p in self.pattern:
                if p == ".":
                    self.code.append("dot")
                if p == "-":
                    self.code.append("-")
            return self.dash.join(self.code)

class S(Letter):
    def __init__(self):
        pattern = ['.', '.', '.']
        super().__init__(pattern)
Steven Parker
Steven Parker
230,231 Points

Here's a few more hints:

  • the error message is misleading, I'd bet that it tested other characters and found the issue there
  • dashes are represented in the pattern as underscores ("_"), not hyphens ("-")
  • the new method should convert dashes into the word "dash"
  • when the parts are joined, there should be hyphens between each word
January Johnson
January Johnson
23,855 Points

OMG! I completely overlooked that. Also, I was way overthinking this! Finally, I got it working with this.

python
lass Letter:
    def __init__(self, pattern=None):
        self.pattern = pattern 

    def __str__(self):
        code_string = []
        for p in self.pattern:
            if p == ".":
                code_string.append("dot")
            if p == "_":
                code_string.append("dash")
        return "-".join(code_string)

Thank you, Steven Parker, so much.