Python: Program for Area of Rectangle, Circle, and Square
Below is the program which calculates the areas of Rectangle, Circle, and Square. It takes the inputs from user such as length and width for Rectangle, radius for Circle, and side of Square for Square.
Code:
length = int(input("Enter the length of the Rectangle "))
width = int(input("Enter the width of the Rectangle "))
radius = int(input("Enter radius of Circle "))
side = int(input("Enter side of the Square "))
class Area:
def __init__(self, length, width, radius, side,):
self.length = length
self.width = width
self.radius = radius
self.side = side
def Rect_area(self):
rect_area = self.length*self.width
print(f"Area of the Rectangle = {rect_area} Sq.Units")
def Cir_area(self):
cir_area = 3.14*self.radius**2
print(f"Area of
circle = {cir_area} Sq.Units")
def Squ_area(self):
squ_area = self.side**2
print(f"Area of Square = {squ_area} Sq.Units")
rectangle = Area(length, width, radius, side)
circle = Area(length, width, radius, side)
square = Area(length, width, radius, side)
rectangle.Rect_area()
circle.Cir_area()
square.Squ_area()
Output:
Enter the length of the Rectangle 5
Enter the width of the Rectangle 6
Enter radius of Circle 4
Enter side of the Square 7
Area of the Rectangle = 30 Sq.Units
Area of circle = 50.24 Sq.Units
Area of Square = 49 Sq.Units
Comments
Post a Comment