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

Melita Carty
Melita Carty
14,421 Points

Can't work out what's wrong with my code? (Output formatting issue?)

I've managed to get this to work in Workspaces by tweaking with print/return, but I can't work out how to get it to work in the Challenge itself. Can anyone see what I'm doing wrong? Thanks.

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

    def __str__(self):
        morse=""
        y=0
        for x in self.pattern:
            if x=='.':morse+='dot'
            if x=='_':morse+='dash'            

            if y<len(self.pattern)-1:morse+='-'
            y+=1  

        return morse



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

1 Answer

Ryan S
Ryan S
27,276 Points

Hi Melita,

Your code is correct, but it seems you have a slight indentation issue. If you look at your __init__ definition in the Letter class, the "def" keyword is indented by one extra space. If you fix that it should pass.