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 trialEldin Guzin
6,010 PointsHow do I join the strings together by a hyphen and am I on the right track here ? ---- Morse task ----
Thanks in advance
class Letter:
def __init__(self, pattern=None):
self.pattern = pattern
for dot in pattern:
def __str__(dot):
if dot = ".":
dot = "dot"
elif dot = "_":
dot = "dash"
return dot
class S(Letter):
def __init__(self):
pattern = ['.', '.', '.']
super().__init__(pattern)
2 Answers
KRIS NIKOLAISEN
54,972 PointsTo join with a hyphen you can use Python's join method. There is a quick tutorial here.
Some additional hints:
- Your for loop should be inside the
__str__
method - The only parameter for this method should be
self
- You should iterate over
self.pattern
- Use comparison operators in your if conditions. You are currently using assignment operators.
- In your method create a new list variable and append "dot" or "dash" to that.
- Then outside the loop return the joined list
KRIS NIKOLAISEN
54,972 PointsA single equals sign assigns the value on the right to the variable on the left (and causes a syntax error in Python when used in an if statement)
if dot = ".":
A double equals sign compares the right and left sides to see if they are the same
if dot == ".":
Other comparison operators include greater than, less than, not equal to, etc.
Eldin Guzin
6,010 Pointsgot it! You are awesome
Eldin Guzin
6,010 PointsEldin Guzin
6,010 PointsWhat do you mean by saying "Use comparison operators in your if conditions. You are currently using assignment operators", What are comparison operators ? Anyways thanks for your great answer