Commit ea54cc90 by arjun.b

Assignment 1

parent 40e5dddd
# 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())
print("area of rectangle=",obj_rect.area())
print("perimeter of rectangle=",obj_rect.perimetr)
# initializing the radius of the circle
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())
print("area of circle=", obj_cir.area(), "\n", "perimeter of circle", obj_cir.perimetr())
# initializing the side of the square
side = float(input("enter the side of the square"))
obj_sqr = Square(side)
print("area=", obj_sqr.area(), "\n", "perimeter", obj_sqr.perimtr())
obj_sqr = Square(side) # create the object of the class Square
print("area of square=", obj_sqr.area(), "\n", "perimeter of square", obj_sqr.perimtr())
class myException(Exception):
pass
class Circle:
def __init__(self, radius):
self.radius = radius
def area(self):
try:
return 3.14 * self.radius * self.radius
except myException:
print("exception occurred")
def perimetr(self):
try:
return 2 * 3.14 * self.radius
except myException:
print("exception occurred")
class myException(Exception):
pass
class Rect:
def __init__(self, length, width):
self.length = length
self.width = width
def area(self):
try:
return self.length * self.width
except myException:
print("exception occurred")
def perimtr(self):
def perimetr(self):
try:
return 2 * (self.length + self.width)
except myException:
print("exception occurred")
finally:
print("-----------")
\ No newline at end of file
class myException(Exception):
pass
class Square:
def __init__(self, side):
self.side = side
......@@ -5,6 +7,11 @@ class Square:
def area(self):
try:
return self.side * self.side
except myException:
print("exception occurred")
def perimtr(self):
try:
return 4 * self.side
except myException:
print("exception occurred")
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