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 trialMaximilian Tan
5,570 Pointsmorse.py challenge code doesn't work
I tried the attached code in my IDE and it works.
However the output here in the code challenge's IDE does not allow me to pass.
Appreciate it if anyone can point me to my mistake.
Thanks
class Letter:
def __init__(self, pattern=None):
self.pattern = pattern
def __iter__(self):
yield from self.pattern
def __str__(self):
output = []
for blip in self:
if blip == '.':
output.append('dot')
else:
output.append('dash')
return '-'.join(output)
@classmethod
def from_string(cls, string):
new_list = []
string_list = string.split('-')
for i in string_list:
if i.lower() == 'dash':
new_list.append('_')
elif i.lower() == 'dot':
new_list.append('.')
else:
pass
return cls(new_list)
class S(Letter):
def __init__(self):
pattern = ['.', '.', '.']
super().__init__(pattern)
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, Maximillian! From what I can tell, you haven't made an error. Your code, as is, when copied and pasted into the challenge works for me and passes with flying colors. This makes me suspicious about a possible caching problem. Try copy/pasting your code from here then clearing your browser cache. It could also be something cached on the server side in which case you might have to log out and back in again.
But your code works! Good job! Hope this helps
Erik Quiroga
3,474 PointsErik Quiroga
3,474 PointsJennifer Nordell, you're right it must be a caching error. What I did was erase the code from the challenge, pasted my own code from my editor, and clicked the "check work" button. It passed!