# This Program generates a class that is aimed at finding the Area and Perimeter
# in a rectangle.
import math
class Rectangle:
def __init__(self, height, width):
self.width = 2
self.height = 1
def getArea(self):
area = self.width * self.height
return area
def getPerimeter(self):
perimeter = 2 * (self.width + self.height)
return perimeter
def setHeight(self, height):
self.height = height
def setWidth(self, height):
self.width = width
def main():
rectangle1 = Rectangle()
print("The area of the Rectangle of radius" , Rectangle1.width, Rectangle1.height, "is",\
Rectangle1.getArea())
main()
There are so many error in your program.
function init takes two argument, and you are not providing any argument while creating object Rectangle()
function setWidth(self, height)
, and inside function you are using variable width
.
Rectangle1
If you fix these your program should work
There are multiple mistakes. You are calling Rectangle class without height and width (you could also pass them as default parameters).
Your indentation is broken in the class.
You have initialized rectangle1 but calling Rectangle1, hence the additional errors.
import math
class Rectangle:
def __init__(self, height, width):
self.width = 2
self.height = 1
def getArea(self):
area = self.width * self.height
return area
def getPerimeter(self):
perimeter = 2 * (self.width + self.height)
return perimeter
def setHeight(self, height):
self.height = height
def setWidth(self, height):
self.width = width
def main():
rectangle1 = Rectangle(4,2)
print("The area of the Rectangle of radius" , rectangle1.width, rectangle1.height, "is",\
rectangle1.getArea())
main()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With