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

Pitrov Secondary
Pitrov Secondary
5,121 Points

I can't get this right.

How do I do this challenge? I can't get this to work. Here's my code.

morse.py
class Letter:
    def __init__(self, pattern=None):
        self.pattern = pattern
        self.new_str = ''
    def __str__(self):
        new_str= ''
        for item in self.pattern:
            if item == '.':
                new_str += 'dot'
            elif item == '_':
                new_str += 'dash'
            new_str += '-'
        new_str -= '-'
        return new_str




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

1 Answer

You can't subtract from a string with -. You can use slice syntax to get the string without the last -:

new_str = new_str[:-1]
return new_str

or

return new_str[:-1]
Pitrov Secondary
Pitrov Secondary
5,121 Points

Hi. I am a bit suprised, but it works now, thanks!