#*****geometricClass.py*****

# Python Geometric class

class geometryClass:
def __init__(self,length,breath,radius,height,base1,base2):
self.length=length
self.breath=breath
self.radius=radius
self.height=height
self.base1=base1
self.base2=base2
def square(self):
area_sqr=self.length ** 2
return area_sqr;
def rectangle(self):
area_rect=self.length*self.breath
return area_rect;
def circle(self):
area_circle=3.14*(self.radius ** 2)
return area_circle;
def triangle(self):
area_tri=0.5*self.base1*self.height
return area_tri;
def parallelogram(self):
area_para=self.base2*self.height
return area_para;
def trapezoid(self):
area_trap=0.5*self.base1*self.base2*self.height;
return area_trap;

shape=geometryClass(5,3,2,4,6,3);
print shape.square();

# *****Shape.py******
# this page imports the Shape class and implements those functions

from geometryClass import *

print '\n *** Area of various Geometric shapes***'
print ' 1. Square \n 2. Rectangle \n 3. Circle \n 4. Triangle \n 5. Parallelogram \n 6. Trapezoid'
option=input('\n Select the geometric shape to find the area:')

if option==1:
length=input('Enter the length of square side:')
area_sqr=geometryClass(length,0,0,0,0,0);
print ('Area of square:',area_sqr.square());
elif option==2:
length=input('Enter the length of rect: ')
breath=input('Enter the breadth of rect: ')
area_rect=geometryClass(length,breath,0,0,0,0)
print ('Area of Rectangle:',area_rect.rectangle());
elif option==3:
radius=input('Enter the radius of circle: ')
area_circle=geometryClass(0,0,radius,0,0,0)
print ('Area of Circle:',area_circle.circle());
elif option==4:
base=input('Enter the base of triangle: ')
height=input('Enter the height of triangle: ')
area_tri=geometryClass(0,0,0,height,base,0)
print ('Area of Triangle:',area_tri.triangle());
elif option==5:
base=input('Enter the base of parallelogram: ')
height=input('Enter the height of parallelogram: ')
area_par=geometryClass(0,0,0,height,0,base)
print (' Area of parallelogram: ',area_par.parallelogram());
elif option==6:
base1=input('Enter the base1 of trapezoid: ')
base2=input('Enter the base2 of trapezoid: ')
height=input('Enter the height of trapezoid: ')
area_par=geometryClass(0,0,0,height,base1,base2)
print (' Area of trapezoid: ',area_par.trapezoid());
else:
print 'No Geometric shape existing with this selection. please try back.'

Output:

0 Comments:

Post a Comment



Newer Post Older Post Home