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

Bummer: Try Again. How can I debug the code in my workspace?

How can I feed the string into str and see the results?

Thinking, pls verify, print(S.str(['.', '.', '.']))

Thank you in advance...

morse.py
class Letter:
    code = []
    def __init__(self, pattern=None):
        self.pattern = pattern

    def __str__(self, pattern):
        for item in pattern:

            if item is '.':
                code.append = 'dot'

            elif item is '_':
                code.append = 'dash'

        return ('-'.join(code))



class S(Letter):
    def __init__(self):
        pattern = ['.', '.', '.']
        super().__init__(pattern)

4 Answers

Steven Parker
Steven Parker
231,248 Points

Yea, those challenge messages can be pretty terse. You can copy the challenge to the workspace for debugging, but be careful because the workspace has no idea what the objective is!

And here's a few hints:

  • this method shouldn't take an argument (just the "self" parameter)
  • when you refer to "pattern", be sure to use the "self." prefix
  • instead of the identity operator ("is"), you probably want to use the equality comparison ("==")
  • append is a method, so the argument should go in parentheses after the method name

I will check it out. Thank you.

I'm getting a SyntaxError: Can't assign the function call pointing to code.append(item) = 'dash' when I run in my Workspace

class Letter: code = [] def init(self, pattern=None): self.pattern = pattern

def __str__(self):
    for item in self:

        if item == '.':
            code.append(item) = 'dot'

        elif item == '_':
            code.append(item) = 'dash'

        print(code)

    return ('-'.join(code))

class S(Letter): def init(self): pattern = ['.', '.', '.'] super().init(pattern)

class Letter: code = [] def init(self, pattern=None): self.pattern = pattern

def __str__(self):
    for item in self:

        if item == '.':
          code.append(item) = 'dot'

        elif item == '_':
          code.append(item) = 'dash'

    return ('-'.join(code))

class S(Letter): def init(self): pattern = ['.', '.', '.'] super().init(pattern)

Steven Parker
Steven Parker
231,248 Points

Method calling syntax doesn't use an assignment operator:

          code.append(item) = 'dot'   # instead of this
          code.append('dot')          # try this

And remember, "self" is the object, the pattern is "self.pattern".

Topher Knoll
Topher Knoll
3,572 Points

When I run my code in PyCharm I get the output, "dot-dot-dot," which I thought is what we're looking for. Why when I run it in the code challenge it says the output is, "dash-dash-dash-dot-dash-dash-dot-dot-dot-dot?"

Steven Parker
Steven Parker
231,248 Points

The challenge performs a more thorough test than just one letter.