Answer:
The complete program is as follows:
class Rectangle:
def __init__(self, length, width):
self.width = abs(width)
self.length = abs(length)
def area(self):
area = self.length * self.width
return area
def perimeter (self):
perimeter = 2 * (self.length + self.width)
return perimeter
if __name__ == '__main__':
l = float(input(": "))
w = float(input(": "))
r = Rectangle(l, w)
print('Perimeter =', r.perimeter())
print('Area =', r.area(), end='')
Step-by-step explanation:
This defines the class:
class Rectangle:
This gets the parameters from maiin
def __init__(self, length, width):
This sets the width
self.width = abs(width)
This sets the length
self.length = abs(length)
The area function begins here
def area(self):
Calculate the area
area = self.length * self.width
Return the calculated area back to main
return area
The perimeter function begins here
def perimeter (self):
Calculate the perimeter
perimeter = 2 * (self.length + self.width)
Return the calculated perimeter back to main
return perimeter
The main begins here
if __name__ == '__main__':
This gets input for length
l = float(input(": "))
This gets input for width
w = float(input(": "))
This passes the inputs to the class
r = Rectangle(l, w)
This prints the returned value for perimeter
print('Perimeter =', r.perimeter())
This prints the returned value for area
print('Area =', r.area(), end='')