Question

In: Computer Science

Write the class Square that takes X,Y and Side as parameters (these are used in the...

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

Solutions

Expert Solution


"""
  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()


Related Solutions

Given a square of side a, lying in the x-y plane, with one corner at the...
Given a square of side a, lying in the x-y plane, with one corner at the origin and the two adjacent sides aligned with the x and y axis, respectively. Three of the corners of the square are occupied by fixed charges: two equal positive charges Q each at (a,0) and (0.a), and a negative charge -q at (a,a). There is NO charge at the origin (0.0). We want to find and discuss the NET electric field AT THE ORIGIN...
Solve using variation of parameters. y′′ + y = sec2(x)
Solve using variation of parameters. y′′ + y = sec2(x)
Matlab Create/write a function that takes an input of x and y data, and a string...
Matlab Create/write a function that takes an input of x and y data, and a string (either linear? or quadratic), sets up a linear system of equations (Ax = b), and solves and plots the model.
Four protons are placed in the vertices of a square with a side of 2 x...
Four protons are placed in the vertices of a square with a side of 2 x 10^-9 m. A fifth proton is initially on the square perpendicular to its center, at a distance of 2 x 10^-9 m from it. Calculate (a) the minimum initial velocity that the fifth proton needs to reach the center of the square, (b) its initial and final accelerations. (c) Make a graph of the proton's potential energy as a function of its distance to...
Four protons are placed in the vertices of a square with a side of 2 x...
Four protons are placed in the vertices of a square with a side of 2 x 10-9 m. A fifth proton it is initially on the perpendicular to the square by its center, at a distance of 2 x 10-9 m from it. Calculate (a) the minimum initial velocity that the fifth proton needs to reach the center of the square, (b) its initial and final accelerations. (c) Make a graph of the proton's potential energy as a function of...
use variation of parameters to solve y''+y'-2y=ln(x)
use variation of parameters to solve y''+y'-2y=ln(x)
please solve using jupyter notebook . 10.9- (Square Class) Write a class that implements a Square...
please solve using jupyter notebook . 10.9- (Square Class) Write a class that implements a Square shape. The class should contain a side property. Provide an __init__ method that takes the side length as an argument. Also, provide the following read-only properties: a) perimeter returns 4 × side. b) area returns side × side. c) diagonal returns the square root of the expression (2 × side2). The perimeter, area and diagonal should not have corresponding data attributes; rather, they should...
Let X and Y be jointly normal random variables with parameters E(X) = E(Y ) =...
Let X and Y be jointly normal random variables with parameters E(X) = E(Y ) = 0, Var(X) = Var(Y ) = 1, and Cor(X, Y ) = ρ. For some nonnegative constants a ≥ 0 and b ≥ 0 with a2 + b2 > 0 define W1 = aX + bY and W2 = bX + aY . (a)Show that Cor(W1, W2) ≥ ρ (b)Assume that ρ = 0.1. Are W1 and W2 independent or not? Why? (c)Assume now...
in C++ Write a definition for a class ‘point’ to describe a point with coordinates (X,Y)...
in C++ Write a definition for a class ‘point’ to describe a point with coordinates (X,Y) in 2-D space. The private data members are the coordinates X and Y of type ‘double’. The public member functions are: A default constructor (no parameters) to initialize X and Y to zero. An explicit value constructor with two parameters to initialize the values of X and Y. Two functions, one to set the X value and the other to set the Y value...
Use method of variation of parameters to solve y'' + y = sin^2(x)
Use method of variation of parameters to solve y'' + y = sin^2(x)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT