老师好,我用input()实现了自己随意输入x,y,width,height数据,但是实操提示的不输入数据默认x=0,y=0,width=100,height=100应该怎么定义
import turtle
class MyRectangke:
def __init__(self, x, y, width, height):
self.x = x
self.y = y
self.width = width
self.height = height
def getArea(self):
s = self.width * self.height
print("矩形面积:{0}".format(s))
def getPerimeter(self):
l = (self.width + self.height) * 2
print("矩形周长:{0}".format(l))
def draw(self):
turtle.penup()
turtle.goto(self.x, self.y)
turtle.pendown()
turtle.goto(self.x + self.height, self.y)
turtle.goto(self.x + self.height, self.y - self.width)
turtle.goto(self.x, self.y - self.width)
turtle.goto(self.x, self.y)
turtle.done()
x = int(input('请输入x坐标: '))
y = int(input('请输入y坐标: '))
width = int(input('请输入width: '))
height = int(input('请输入height: '))
s = MyRectangke(x, y, width, height)
s.getArea()
s.getPerimeter()
s.draw()