Question: Python Please help! Given the following class definition, implement the methods def perimeter(self), def diagonalLength(self), and def display(self, length_horizontal = True, character = '*') import
Python Please help!
Given the following class definition, implement the methods def perimeter(self), def diagonalLength(self), and def display(self, length_horizontal = True, character = '*')
import math
class Rectangle:
# initializer with default length = 4 and default width = 3
def __init__(self, length = 4, width = 3):
self.length = length
self.width = width
# method that returns the area of the rectangle
def area(self):
return self.length * self.width
# method that prints the following information to the standard output terminal:
# length, width, area, perimeter, diagonal length def printInfo(self): print('Length is ' + str(self.length)) print('Width is ' + str(self.width)) print('Area is ' + str(self.area())) print('Perimeter is ' + str(self.perimeter())) print('Diagonal length is ' + str(self.diagonalLength()))
# method that returns the perimeter of the rectangle
def perimeter(self):
#Fill in the necessary code below
Part 2 # method that returns the diagonal length of the rectangle
def diagonalLength(self):
#Fill in the necessary code below
# method that prints the rectangle to the standard output terminal
# default values for optional parameters are True and '*'
# length_horizontal determines if the rectangle should be printed so that the longer side (length) is
# horizontal vs. vertical, character is the type of character used to print the rectangle
# Sample output is shown for the following method calls
r1 = Rectangle()
r1.printInfo()
r1.display()
print()
r2 = Rectangle(10, 2)
r2.display(True)
print()
r2.display(False)
print()
r2.display(False,'g')
print()
Length is 4 Width is 3 Area is 12 Perimeter is 14 Diagonal length is 5.0
* * * *
* * * *
* * * * * * * * * *
* * * * * * * * * *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
g g
g g
g g
g g
g g
g g
g g
g g
g g
g g
* *
def display(self, length_horizontal = True, character = '*'):
#Fill in the necessary code below
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
