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

morse.py. How do I troubleshoot morse.py from Python console.

I am trying to troubleshoot this Challenge in Workshop. I feel like I am pretty close, but when trying to check in Console I am lost on how to request for results. The only step I am confident about is the "from morse import S", but after this not sure how to walk through my own manual test.

Any advice would be appreciated.

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

    def __str__(self):
        j="-"
        morse_list=[]
        for item in self.pattern:
            if item == ".":
                morse_list.append("dot")
            if item == "_":
                morese_list.append("dash")
        return j.join(morse_list)

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

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

It would be difficult to debug solely using the S class because everything in the class is hard-coded. You can create other classes that inherit from the Letter class, or you may wish to import the Letter class and to test if there is issue in that code.

When debugging, it sometimes helps to look at what part of the code has not yet been exercised. This concept is called coverage testing. In the case of using S() are all branches of the Letter.__str__ method exercised?

Try instantiating other letters using Letter(pattern=new_pattern) where new_pattern has various values different from the pattern used in S. The error should be found quite quickly.

Post back if you need a bigger hint. Good luck!!