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

need a help

can someone help on construction task python

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

def from__string(cls, string):
    list = from_string("-")
    paattern = []
    for x in from_string:
        if x == "dash":
            pattern.append("-")
            return cls(pattern)

    def __iter__(self):
        yield from self.pattern

    def __str__(self):
        output = []
        for blip in self:
            if blip == '.':
                output.append('dot')
            else:
                output.append('dash')
        return '-'.join(output)


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

1 Answer

Steven Parker
Steven Parker
229,785 Points

Here's a few hints:

  • the entire method definition must be indented
  • the instructions say this should be done with "\@classmethod"
  • instead of "from__string", the method name should be "from_string" (just one underscore)
  • this method shouldn't be recursive (should not call itself)
  • you may want to "split" the string argument into a list
  • the word "paatern" should be "pattern" (just one "a")
  • since "list" is a keyword it's not a good choice for a variable name
  • instead of a hyphen ("-"), a "dash" should be represented as an underscore ("_")
  • the method should also convert "dot" into a pattern
  • the "return" should not occur until the loop is finished

@classmethod def from_string(cls, dash_dot_string): dash_dot_list = dash_dot_string.split('-') pattern_list = [] for item in dash_dot_list: if item == 'dot': pattern_list.append('.') else: pattern_list.append('_')

    return cls(pattern_list)

cant pass

Steven Parker
Steven Parker
229,785 Points

I'd guess you might have one or more indentation errors, since the code looks good otherwise but there's no way to tell if the indentation is correct without markdown formatting.

If you don't find a spacing issue, add formatting to the above to allow it to be checked.