Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

50 Tips And Tricks For MongoDB Developers Get The Most Out Of Your Database

Authors: Kristina Chodorow

1st Edition

1449304613, 978-1449304614

More Books

Students also viewed these Databases questions