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

Tiana Manzano
PLUS
Tiana Manzano
Courses Plus Student 2,248 Points

morse.py

I'm not sure why I am getting the error answer if my output succesfully produces 'dot-dot-dot'. Did I do something incorrectly?

morse.py
class Letter:
    def __init__(self, pattern=None):
        self.pattern = pattern
    def __str__(self):
       morse = " "
       for item in self.pattern:
            if item == '.':
                morse += "dot"
            elif item == "_":
                morse += "dash"
            morse += "-"
       morsec = morse[:-1]
       return morsec

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

3 Answers

A space is considered a character in the string so you weren't producing 'dot-dot-dot'. You were producing ' dot-dot-dot' (spacedot-dot-dot). If you initialize an empty string there is no space.

You have a leading space because you initialized morse = " ". Try morse = "".

Tiana Manzano
Tiana Manzano
Courses Plus Student 2,248 Points

hey!! that totally worked! But would it be possible for you to explain why please?

When you put white space inside your quotes python considers it a character eg. " ". However when there is no space it is considered an empty string eg. "". So the difference is the white space and no space inside quotes of your initialized string variable 'morse'