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
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): 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
return (self.__width + self.__height) * 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started