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


I must be missing something obvious. OOP Morse Challenge.

I must be missing something obvious about classes and methods here. When I run the code below as a classless function in the work-space (with some obvious substitutions - as seen below), it checks out. I try to run it in the code chellenge and I get an error.

Here's the code in work-space: def morse(pattern): converted = [] for item in pattern: if item == ".": converted.append("dot") elif item == "_": converted.append("dash") print('-'.join(converted))


More than just showing me how to pass the challenge, WHAT am I missing about classes?

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

    def __str__(self):
        converted = []
        for item in self.pattern:
            if item == ".":
            elif item == "_":
        return '-'.join(converted)

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

The code passes. What error did you receive?

1 Answer

I just copy-pasted and it passed... bahahaha.

Up until that try, I kept getting the generic "Bummer" message.

I must have made it bug somehow. On the other hand, it DID lead me to a much more practiced exploration of classes, methods and instances. So... not all bad. Frustrating, but informative! 4.5 stars. Would definitely recommend.

Also, Kris, you're two-for-two on the answers and as a level-0 pc, I appreciate it.