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 trialCross Ender
9,567 PointsKeeps returning "Bummer!" Here's my code: Try it out, it works, I tested it on IDLE.
(@classmethod goes up here) def from_string(string): pattern = [] current_wrd = "" for letter in string: current_wrd += letter if current_wrd == "dash": pattern.append("_") current_wrd = "" elif current_wrd == "dot": pattern.append(".") current_wrd = "" elif current_wrd == "-" current_wrd = "" return pattern
Test it out, it has been proven to work =)
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(string):
pattern = []
current_wrd = ''
for letter in string:
current_wrd += letter
if current_wrd == 'dash':
pattern.append('_')
current_wrd = ''
elif current_wrd == 'dot':
pattern.append('.')
current_wrd = ''
elif current_wrd == '-':
current_wrd = ''
return pattern
class S(Letter):
def __init__(self):
pattern = ['.', '.', '.']
super().__init__(pattern)
2 Answers
Steven Parker
231,269 PointsBe careful about testing a challenge in an external IDLE.
If you have misunderstood the challenge, it's also very likely that you will misinterpret the results.
In this case you missed where the instructions said that your method "creates an instance with the correct pattern". But you're returning the pattern itself instead.
Also, remember that a @classmethod takes an extra argument to represent the class itself (which might be useful when your loop completes!).
Cross Ender
9,567 PointsThanks for that, (I have a reputation for missing that kinda stuff XD) And also, IDLE is a standalone shell. Rather, the shell that comes with python when you download it.
Steven Parker
231,269 PointsSure, I meant "external" in the sense of "external to the challenge". Anything other than the challenge will not detect if the results are correct.