代码:
import turtle as t
class MyRectangle:
def __init__(self,x=0,y=0,width=100,height=100):
self.x=x
self.y=y
self.width=width
self.height=height
def getArea(self):
return self.width*self.height
def getPerimeter(self):
return 2*(self.width+self.height)
def draw(self):
t.penup()
t.goto(self.x,self.y)
t.pendown()
t.goto(self.x,self.y-self.height)
t.goto(self.x+self.width,self.y-(self.height))
t.goto(self.x+self.width,self.y)
t.goto(self.x,self.y)
t.done()
yida=MyRectangle(-50,-50,200,280)
print(yida.getArea())
print(yida.getPerimeter())
yida.draw()
老师,先用draw()方法以后就打印不出来面积和周长了,这是为什么? 必须 getArea ,getPerimeter方法放在draw方法前面才能打印出来,这是因为turtle.done()的某些机制吗? 求老师帮忙