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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!