Respuesta :
Answer:
class Rectangle:
def __init__(self, length=1, width=1):
self.length = length
self.width = width
def Area(self):
return self.length * self.width
def Perimeter(self):
return 2 * (self.length + self.width)
def Print(self):
print(str(self.length) + " X " + str(self.width))
l = float(input("Enter the length: "))
w = float(input("Enter the width: "))
a = Rectangle(l, w)
print(str(a.Area()) + " " + str(a.Perimeter()))
a.Print()
Explanation:
Create a class called Rectangle
Create its constructor, that sets the length and width
Create a method Area to calculate its area
Create a method Perimeter to calculate its perimeter
Create a Print method that prints the rectangle in the required format
Ask the user for the length and width
Create a Rectangle object
Calculate and print its area and perimeter using the methods from the class
Print the rectangle
Answer:
class Rectangle():
def __init__(self, l, w):
self.len = l
self.wi = w
def area(self):
return self.len*self.wi
def perimeter(self):
return self.len+self.len+self.wi+self.wi
def printing(self):
print('{} Lenght X Width {}'.format(self.len, self.wi))
length = int(input("enter the length "))
width = int(input("enter the width "))
newRectangle = Rectangle(length, width)
newRectangle.printing()
print("Area is: ")
print(newRectangle.area())
print("The perimeter is: ")
print(newRectangle.perimeter())
Explanation:
The class rectangle is defined with a constructor that sets the length and width
As required the three methods Area, perimeter and printing are also defined
The input function is used to prompt and receive user input for length and width of the rectangle
An object of the Rectangle class is created and initalilized with the values entered by the user for length and width
The three methods are then called to calculate and return their values