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 trialdaniel steinberg
14,651 PointsMorse Code Challenge
my outout seems correct..I got dot-dot-dot. Why does it say it's wrong?
from question: "...I've included an S class as an example (I'll generate the others when I test your code) and it's str output should be "dot-dot-dot"...."
message:
Bummer: Didn't get the right string output. Got: dot-dot-dot for S()
code: class Letter: def init(self, pattern=None): self.pattern = pattern def str(self): test=[] for x in self.pattern: if x == ".": test.append("dot") elif x == "-": test.append("dash") return "-".join(test)
class S(Letter): def init(self): pattern = ['.', '.', '.'] super().init(pattern)
class Letter:
def __init__(self, pattern=None):
self.pattern = pattern
def __str__(self):
test=[]
for x in self.pattern:
if x == ".":
test.append("dot")
elif x == "-":
test.append("dash")
return "-".join(test)
class S(Letter):
def __init__(self):
pattern = ['.', '.', '.']
super().__init__(pattern)
2 Answers
KRIS NIKOLAISEN
54,971 PointsYou have elif checking for a hyphen when it should be checking for an underscore.
This
elif x == "-":
should be:
elif x == "_":
KRIS NIKOLAISEN
54,971 PointsTry:
test=S()
print(test)
daniel steinberg
14,651 Pointsty. that worked. .so when a class has another class passed to it as an argument . what is the diff between test=S and test =S() ?
test = S seems to run with no errors
thanks again
daniel steinberg
14,651 Pointsdaniel steinberg
14,651 PointsTY! one more question please. In general I love Treehouse but this section/instructor I find hard to follow.
how do I access the str method? ex: test=S print(test) prints: <class '__main__.S'> not "dot_dot_dot"
if I try to access the method test=S test.str()
i get: TypeError: str() missing 1 required positional argument: 'self'