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 Technical Interview Prep: Python Basics Basic Python Let's Get Together

Hi I need help with this code I'm not sure what I'm doing wrong its really tricky. Please could you help me.

I'm really struggling with this one I keep getting an error message that the word Tree should be the output.

join.py
def morse_code(word):
    morse_dict = {
        'a': 'dot-dash',
        'b': 'dash-dot-dot-dot',
        'c': 'dash-dot-dash-dot',
        'd': 'dash-dot-dot',
        'e': 'dot',
        'f': 'dot-dot-dash-dot',
        'g': 'dash-dash-dot',
        'h': 'dot-dot-dot-dot',
        'i': 'dot-dot',
        'j': 'dot-dash-dash-dash',
        'k': 'dash-dot-dash',
        'l': 'dot-dash-dot-dot',
        'm': 'dash-dash',
        'n': 'dash-dot',
        'o': 'dash-dash-dash',
        'p': 'dot-dash-dash-dot',
        'q': 'dash-dash-dot-dash',
        'r': 'dot-dash-dot',
        's': 'dot-dot-dot',
        't': 'dash',
        'u': 'dot-dot-dash',
        'v': 'dot-dot-dot-dash', 
        'w': 'dot-dash-dash',
        'y': 'dash-dot-dash-dash',
        'z': 'dash-dash-dot-dot'
    }
class Letter:
    def __init__(self, pattern=None):
        self.pattern = pattern

    def __str__(self):
        morse = []
        for i in self.pattern:
            if i == '.':
                morse.append("dot")
            if i == "-":
                morse.append("dash")
        return "-".join(morse)

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

1 Answer

Megan Amendola
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher

Hi! First, your code should be written inside of the morse_code function. Second, you should be translating the word being passed into the function into morse code using the provided dictionary morse_dict. So if the word being passed in is "cat", then the output should be "dash-dot-dash-dot-dot-dash-dash". You'll need to find each letter of the word in the dictionary and then combine the morse code to return it translated.