TypeError: unbound method draw() must be called with Body instance as first argument (got Turtle instance instead)
I get that error when I attempt to run my program in python. I have to use the turtle module to draw the body of a car with body class. The class needs to have a init method and a draw method. The init method is supposed to determine fill color and draw is supposed to draw the object.
heres some of my code:
The rest of the code in the draw method is code that draws the body and it works when I separate it from the class in a different program. And it doesn't show but i have imported math and turtle.
I get that error when I attempt to run my program in python. I have to use the turtle module to draw the body of a car with body class. The class needs to have a init method and a draw method. The init method is supposed to determine fill color and draw is supposed to draw the object.
heres some of my code:
Code:
pen=turtle.Turtle() class Body(object): def __init__(self,fillcolor=''): self.fillcolor=fillcolor def draw(self,pen,size=80): """draw the body of your car of given size using pen size is car length/2; fill it if fillcolor is provided""" if self.fillcolor: pen.fillcolor(self.fillcolor) pen.fill(True) #draw the Body
Code:
pen.down() pen.forward(size*3/2) pen.left(45) pen.forward(size/2*math.sqrt(2)) pen.left(90) pen.forward(size/2*math.sqrt(2)) pen.left(45) pen.forward(size*3/2) pen.right(45) pen.forward(size/2*math.sqrt(2)) pen.left(45) pen.forward(size*5/4) pen.left(45) pen.forward(size*1/4*math.sqrt(2)) pen.left(45) pen.forward(size) pen.left(45) pen.forward(size*1/4*math.sqrt(2)) pen.left(45) pen.forward(size*7/4) pen.fill(False) # end filling
Comment