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

What's wrong with my code?

Everything seems ok but after check it says: "Didn't get the right string output. Got: dot-dot-dot for S()"

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

    def __str__(self):
        for index, value in enumerate(self.pattern):
            if value == '.':
                self.pattern[index] = 'dot'
            elif value == ',':
                self.pattern[index] = 'dash'
        return "-".join(self.pattern)


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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Artur Waligóra

Yeah, that error doesn't tell you much and probably could use a bit of tweaking. 😕

Your code is actually correct, but it's not checking for the correct symbols. You are checking for a dot . which is correct. However, you are supposed to check for an underscore _, but seem to be checking for a comma ,. Once you fix that up, it passes!

Nice work! :) :dizzy:

I haven't noticed it before. Thanks for help. It works now