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 trial
Daniel Lee
68 PointsHow do I create a line instance that draws a line from the Line Class I created?
import turtle
<p>
class Line(object):
def __init__(self, start = (0,0), end = (50,50),
pencolor = 'black', pensize = 1):
self.start = start
self.end = end
def __str__(self):
return('Line(beg:{},end:{}'.format(self.beg,self.end))
def draw(self):
self.pensize(self.pensize)
self.pencolor(self.pencolor)
self.up()
self.goto(self.beg)
self.down()
self.goto(self.end)
def main():
turtle.setup(700,400, startx = 0, starty = 0)
line = Line()
line.draw()
turtle.done()
main() </p>
Here's the code. I'm getting an error saying that the line attribute has no attribute pensize.
1 Answer
Daniel Lee
68 PointsFound it! I just had to replace the pen argument with t = turtle in the draw method.
<p>
import turtle
class Line(object):
def __init__(self, start = (0,0), end = (50,50),
pencolor = 'black', pensize = 1):
self.beg = start
self.end = end
self.pensize = pensize
self.pencolor = pencolor
def __str__(self):
return('Line(beg:{},end:{}'.format(self.beg,self.end))
def draw(self, t = turtle):
t.pensize(self.pensize)
t.pencolor(self.pencolor)
t.up()
t.goto(self.beg)
t.down()
t.goto(self.end)
def main():
line = Line()
line.draw()
turtle.done()
main()
</p>