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

What is wrong in my code ?

I do get "dot-dot-dot" as output from str method

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

    def __str__(self):
        set_hif = '-'
        set_list =[]
        for i in self.pattern:
                if i == ".":
                    set_dot = i.replace('.','dot')
                    set_list.append(set_dot)

        result = set_hif.join(set_list)
        print(result)



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

check = S()
check.__str__()

2 Answers

There should only be one list that could contain a combination of dots and dashes:

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

    def __str__(self):
        set_hif = '-'
        set_list = []

        for i in self.pattern:
            if i == ".":
                set_list.append('dot')
            elif i == "_":
                set_list.append('dash')

        return set_hif.join(set_list)

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

You are awsome :-) Thanks

1) What about the dash?

and "dash" for every "_" (underscore)

2) Your method should return instead of print the result

3) This line seems unnecessary

set_dot = i.replace('.','dot')

Wouldn't it be simpler to just use this?

set_list.append('dot')

Thanks for your help :-)

I'am still getting the error as "Bummer: Didn't get the right string output. Got: dot-dot-dot for S()"

class Letter: def init(self, pattern=None): self.pattern = pattern

def __str__(self):
    set_hif = '-'
    set_dot_list = []
    set_dash_list = []

    for i in self.pattern:
            if i == ".":
                set_dot_list.append('dot')
                result = set_hif.join(set_dot_list)

            elif i == "_":

                set_dash_list.append('dash')
                result = set_hif.join(set_dash_list)

    result_value = result
    return result_value

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