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 trialshaun cook
2,141 PointsHelp making this code function in pycharm
Hey, i know this code is very scrappy and more holes then a block of Swiss cheese.
im not after any spoilers on how to complete the challenge just yet, i would just like to be able to get an output from an imputed pattern so i can test and alter my code hopefully you can see what i am trying to achieve .
Thank you
class Letter:
def __init__(self, pattern=None):
self.pattern = pattern
def __str__(self, pattern):
dots = ''
dash = ''
## Some more code will go here
for i in pattern:
if i == '.':
dots += i
print(dots)
## repeat loop for '-'
class S(Letter):
def __init__(self):
pattern = ['.', '.', '.']
super().__init__(pattern)
test = Letter()
1 Answer
Steven Parker
231,248 PointsHere's a few hints:
- the method should not take an argument (other than "self")
- remember to return the string value
- be sure to initialze the test letter with a pattern
- test by printing the object as a string
And here is an example of the last two:
test = Letter(['_', '.', '_', '.'])
print("Morse for C is", test)