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

Christopher Remmel
Christopher Remmel
2,897 Points

Hello! I have attempted this code challenge, and am receiving the correct input. It is not being accepted. Help?

I think what I have written works, but it is marked as wrong. Do you have any ideas?

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

    def __str__(self):
        word_string = ""
        for item in range(len(self.pattern)):
            if self.pattern[item] == ".":
                word_string += "dot"
            elif self.pattern[item] == "-":
                word_string += "dash"
            if item < len(self.pattern)-1:
                    word_string += "-"
        return word_string


class S(Letter):
    def __init__(self):
        pattern = ['.', '.', '.']
        super().__init__(pattern)
David Capella
David Capella
4,126 Points

Also, you might want to practice going from list to string and vice versa because it is more efficient to .append() than +=

1 Answer

Steven Parker
Steven Parker
231,261 Points

The instructions say to print "dash" for every "_" (underscore), but it looks like you are comparing the pattern with a "-" (hyphen) instead.