Question: This is a programe I wrote in python but can't figure out why it dose not work, the requirments are under ther code. class Rectangle:
This is a programe I wrote in python but can't figure out why it dose not work, the requirments are under ther code.
class Rectangle: def _init_(self,width, height): self.width = width self.height = height def area(self): return self.width*self.height def getPerimeter(self): return 2 *(self.width + self.height) def main(): rect1 = Rectangle(4,40) rect2 = Rectangle(3.5,35.7) print("Rectangle 1:") print(rect1.width) print(rect1.height) print(rect1.getArea()) print(rect1.getPerimeter()) print(" Rectangle 2:") print(rect2.width) print(rect2.height) print(rect2.getArea()) print(rect2.getPerimeter()) main ()
7.1 (The Rectangle class) Following the example of the Circle class in Section 7.2, design a class named Rectangle to represent a rectangle. The class contains:
Two data fields named width and height.
A constructor that creates a rectangle with the specified width and height. The default values are 1 and 2 for the width and height, respectively.
A method named getArea() that returns the area of this rectangle.
A method named getPerimeter() that returns the perimeter. Draw the UML diagram for the class, and then implement the class. Write a test program that creates two Rectangle objectsone with width 4 and height 40 and the other with width 3.5 and height 35.7. Display the width, height, area, and perimeter of each rectangle in this order.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
