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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Matthew Martin](https://secure.gravatar.com/avatar/6e1ab766d0a751a1024b63128fe7325a?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Matthew Martin
Python Development Techdegree Student 4,387 PointsLet's Get Together Python Interview Problem
Can't figure out the last dash. This is the error message: Uh oh, I didn't get the correct value returned. It should have been dash-dot-dash-dot-dot-dot for the word 'tree'. Instead, it was dash-dot-dash-dot-dotdot
How do you get the last - in the last part of code??
def morse_code(ball):
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'
}
sav = ""
for letter in word:
if letter in morse_dict:
word1 = list(word)
if letter == word1[(len(word)-1)]:
sav = sav + (morse_dict[letter])
else:
sav = sav + (morse_dict[letter]) + "-"
return sav
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsFirst, it looks like the line that creates the sav
variable needs to be indented or it won't be considered part of the function.
Then, since the first "e" matches the last letter in the challenge's test word, the code is skipping the hyphen after it. You'll need to use a different strategy.
One approach you might use is to create a list of code translations, and then join
them together using a hyphen as the separator.