In: Computer Science
Write the class Square that takes X,Y and Side as parameters (these are used in the __init__ method) Write the method draw that will draw the square at location X,Y of size Side from the __init__ parameters using turtle graphics. Instantiate the class. Call the draw method The result of the program's execution will be to draw a square. Good descriptive comments are vital. No comments, no grade. There should be comments after every line, and you need to explain what is happening in the program.
#python
""" Python program to print a square with square class """ import turtle # define class class Square: # class constructor def __init__(self, x, y, s): self.X = x self.Y = y self.side = s # method to draw a square def drawSquare(self): turtle.penup() turtle.goto(self.X, self.Y) turtle.pendown() for i in range(4): turtle.forward(self.side) turtle.right(90) turtle.penup() # testing square class by declaring an object if __name__ == '__main__': sq = Square(10,10,150) sq.drawSquare()