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

plz help can't understand what to do to pass tihs question?

i'am trying to solve this from past 2 days but i'am unable to pass plz help me with your code ...

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

    @from_string
    def create_dash(cls,string):
        string_list = []
        str = string.split("-")
        for element in string_list:
            if element == "dash":
                string_list.append("-")
            else:
                string_list.append(".")





    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
231,261 Points

You're getting close, but there's a few issues yet:

  • the new method is named "create_dash", but the instructions ask for one named "from_string"
  • the method is marked as "@from_string" but the instructions ask for a "@classmethod"
  • "dash" is converted to a hyphen ("-") but the instructions say to make them underscores ("_")
  • the method should return a new instance with the created pattern loaded

how to return a newinstance with the created pattern loaded

Steven Parker
Steven Parker
231,261 Points

Since the current class is passed in as "cls", it takes the pattern as an argument, and you've created the new pattern in "string_list":

        return cls(string_list)