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

Ian Cole
Ian Cole
454 Points

Morse Code gives Bummer

It gives me a bummer, I took it out of Tree house to the Terminal, And it works fine. I don't understand what is going on. Could I get some insight on what i'm doing wrong here? Thanks

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

    def __str__(self):
        packet = "-"
        staging_packet = []
        for chunk in pattern:
            if chunk == '.':
                x = 'dot'
                staging_packet.append(x)
            elif chunk == '_':
                y = 'dash'
                staging_packet.append(y)
        packet = packet.join(staging_packet)
        return packet

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

1 Answer

Steven Parker
Steven Parker
229,708 Points

Perhaps this code is slightly different from what you tried externally? But the issue is on this line:

        for chunk in pattern:  # this should be: self.pattern
Ian Cole
Ian Cole
454 Points

Thanks! Remembering to use self properly has been a pain in my arse lately.