Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to create a Rectangle data class and an executable program to test it in

ID: 3786301 • Letter: I

Question

I need to create a Rectangle data class and an executable program to test it in Python.

The following needs to be included: NOTE: the area() method returns the area and perimeter() returns the perimeter.

In the executable's main function:

•prompt the user to enter the length and width of a rectangle.

•create a new Rectangle instance with the dimensions entered by the user.

•to verify the above step, print both dimensions using their respective "getter" methods.

•test the area() method by printing the rectangle area accurate to two decimal places.

•test the perimeter() method by printing the rectangle perimeter accurate to two decimal places.

•change the length to 22.345 and change the width to 15.789.

•test the area() and perimeter() methods again. You should get the results shown in the sample output.

SAMPLE OUTPUT

Enter the length 12.45

Enter the width 8.973

Length: 12.45

Width: 8.973

Rectangle area is 111.71

Rectangle perimeter is 42.85

Changed rectangle area is 352.81

Changed rectangle perimeter is 76.27

**This is what I have so far:

This is the response:

Explanation / Answer

class Rectangle:
def __init__(self, length, width):
self.l = length
self.w = width
def perimeter(self):
return (2 * self.l) + (2 * self.w)
def area(self):
return self.l * self.w
def isSquare(self):
return (self.l == self.w)
  
length = float(input("Enter the length: "))
width = float(input("Enter the width: "))

obj = Rectangle(length,width)
print("Length: "+str(length))
print("Width: "+str(width))
print("Rectangle area is "+str(round(obj.area(),2)))
print("Rectangle perimeter is "+str(round(obj.perimeter(),2)))

length = 22.345
width = 15.789
obj = Rectangle(length,width)
print("Changed rectangle area is "+str(round(obj.area(),2)))
print("Changed rectangle perimeter is "+str(round(obj.perimeter(),2)))

Output:

sh-4.3$ python3 main.py                                                                                                                                                                                                                                

Enter the length: 12.45                                                                                                                                                                                                                                

Enter the width: 8.973                                                                                                                                                                                                                                 

Length: 12.45                                                                                                                                                                                                                                          

Width: 8.973                                                                                                                                                                                                                                           

Rectangle area is 111.71                                                                                                                                                                                                                               

Rectangle perimeter is 42.85                                                                                                                                                                                                                           

Changed rectangle area is 352.81                                                                                                                                                                                                                       

Changed rectangle perimeter is 76.27

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote