DESCRIPTION: The program calculates the perimeter of rectangle using formula: Perimeter = 2 * (length + breadth) #Perimeter is calculated using class Rectangle class Rectangle(): #Default constructor will take the parameters def __init__(self, length, breadth): self.length = float(length) self.breadth = float(breadth) #Perimeter is calculated using the below function def perimeter_rect(self): print("The Perimeter of Rectangle is: ", 2 * (self.length + self.breadth)) #main() function is called by __name__ def main(): #Length and Breadth are taken from the user length = input("Enter the length: ") breadth = input("Enter the breadth: ") #An object is created for the Rectangle class #length and read the parameters are passed obj_Rectangle = Rectangle(length, breadth) obj_Rectangle.perimeter_rect() #main() function is searched if __name__ == "__main__": #main function is called main() OUTPUT: Test case: Enter the length: 16 Enter the breadth: 3 The Perimeter of Rectangle is: 38.0
Comments