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!
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
Mario Sanchez Carrion17,541 Points
My code is not passing. Could you take a look?
I believe my loop is OK. If I do this manually in the command line it works, however my code is not passing the challenge.
class Letter: def __init__(self, pattern=None): self.pattern = pattern def __str__(self, pattern): morse =  for item in self.pattern: if "." in self.pattern: morse.append('dot') elif "_" in self.pattern: morse.append('dash') return "-".join(morse) class S(Letter): def __init__(self): pattern = ['.', '.', '.'] super().__init__(pattern) def __str__(self): super().__str__(pattern)
Marcin Lubke13,253 Points
Actually your code is pretty ok, but you have some unnecessary
__str__ method declaration.
You don't need
__str__ declaration inside S class, it will be inherited from the Letter class, also you need to change the declaration of the
__str__ method inside Letter class. You don't have to pass a new argument in here, your pattern is already know as self.patter variable, so you have to change it to:
And here, inside your for loop:
for item in self.pattern: if "." in self.pattern: morse.append('dot') elif "_" in self.pattern: morse.append('dash') return "-".join(morse)
you compare dot and dash to self.pattern. You should compare it to "item". Also in my opinion, it would be better to use "==", but both ways should work.