Question: using python 3: A square is a rectangle which has the same width and height. write the definition of the Square class as a subclass
using python 3:
A square is a rectangle which has the same width and height.
write the definition of the Square class as a subclass of Rectangle
write its constructor method, with parameters for its starting point and its size (do not create any new attributes). It could be called as follows:
s = Square((30, 50), 70)
Below the class definition,
instantiate a Square object
use methods get the following and print the results
the square object
its width
its height
its starting point
its area
its perimeter
Change the Rectangle class three get methods to be getter properties that perform same action as the methods. Add a size getter property to the Square class. It returns the length of a side of the square.
In the code below the class defintions
delete the lines using the area and perimeter methods
use the four getter properties instead of the get methods
class Rectangle: def __init__(self,start,width,height): self.__start = start self.__width = width self.__height = height
def getWidth(self): return self.__width
def getHeight(self): return self.__height
def getStartPoint(self): return self.__start
def __str__(self): return 'start={} w={} h={}'.format(str(self.__start),self.__width,self.__height)
def area(self): return self.__width * self.__height
def perimeter(self): return (self.__width + self.__height) * 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
