Question
Im having a little trouble with this question. Here are the instructions. Desing a class named Rectangle to represent a rectangle. The class contains the
Im having a little trouble with this question. Here are the instructions.
Desing a class named Rectangle to represent a rectangle. The class contains the following:
1. Two data fields named width and height
2. A constructor that creates a rectangle with a specific height and width. The default values are 2 for the width and 1 for the height.
3. A method named getArea() that returns the area of this rectangle.
4. A method named getPerimeter() that returns the perimeter.
write and test a program (in the same file as the class) that creates two rectangle objects one with width 3 and height 30 and the other with width 3.7 and height 35.5 display the width, height, area, and perimeter of each rectangle in this order
Here is what I have so far but I dont know how to do the second part with the width of 3 and height of 30.
import math class Rectangle: def __init__(self, height = 1, width = 2): self.height = height self.width = width def getArea(self): return self.height * self.width def getPerimeter(self): return (2*self.height)+(2*self.width) myRectangle = Rectangle() yourRectangle = Rectangle() print("the area of myRectangle is", myRectangle.getArea(), "and the perimeter is", yourRectangle.getPerimeter())
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started