Commit 40e5dddd by arjun.b

Assignment 1

parent 1de11e8b
# importing the modules
from shape.rectangle import Rect
from shape.Circle import Circle
from shape.square import Square
# collecting the length and width of the rectangle
length = float(input("enter the length of the rectangle"))
width = float(input("enter the width of the rectangle"))
obj_rect = Rect(length, width) # create the object of the class Rect
print("area=", obj_rect.area())
print("perimeter=", obj_rect.perimtr())
radius = float(input("enter the radius"))
obj_cir = Circle(radius) # create the object of the class Circle
print("area=", obj_cir.area(), "\n", "perimeter", obj_cir.perimetr())
side = float(input("enter the side of the square"))
obj_sqr = Square(side)
print("area=", obj_sqr.area(), "\n", "perimeter", obj_sqr.perimtr())
class Circle:
def __init__(self, radius):
self.radius = radius
def area(self):
return 3.14 * self.radius * self.radius
def perimetr(self):
return 2 * 3.14 * self.radius
class Rect:
def __init__(self, length, width):
self.length = length
self.width = width
def area(self):
return self.length * self.width
def perimtr(self):
return 2 * (self.length + self.width)
class Square:
def __init__(self, side):
self.side = side
def area(self):
try:
return self.side * self.side
def perimtr(self):
return 4 * self.side
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment