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

tomtrnka
tomtrnka
9,780 Points

Please heeelp .)) Morse code challenge: __str__ representation of Letter.instance

I spent like 30minutes on this challenge, trying to figure out what I missed and I just dont see it.. The challenges gets frustrating at this stage, this is second challenge in a row which Im not able to finish by myself :(

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

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

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

1 Answer

Steven Parker
Steven Parker
230,995 Points

Very close indeed! Just one little syntax issue — there should be a colon (:) at the end of the "def" line.