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

Sam Gutierrez
Sam Gutierrez
6,791 Points

my __str__ method should output "dot-dot-dot" but errors says, wrong string, got "dot-dot-dot".

Error: Bummer: Didn't get the right string output. Got: dot-dot-dot for S() What else do I need to fix? This is not the first coding challenging where correct output was counted wrong.

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

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

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

1 Answer

Scott Bailey
Scott Bailey
13,190 Points

I found two typos that I think are causing your problem.

First one is in the elif statement, you're using an "-" instead of "_".

Second one is a misspelling of "morse", you had "morese".

elif letter == "-":
                morese_code.append("dash")

Once you change them it passes no problem! Good work

def __str__(self):
        morse_code = []
        for letter in self.pattern:
            if letter == ".":
                morse_code.append("dot")
            elif letter == "_":
                morse_code.append("dash")
        morse_code = "-".join(morse_code)
        return morse_code
Sam Gutierrez
Sam Gutierrez
6,791 Points

Thanks. I might have been staring at the screen too long. I caught the typo early on but must have overlooked the check for "_" instead of "-". I know my very first attempt though I didn't even use an elif. I just used else and it didn't work (could have been the typo...probably staring at this screen too long lol)