Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

1. Explain the 2nd world war. 2. Who is the father of history?

Answered: 1 week ago