Open S1d123 opened 2 years ago
import math
class circle():
def init(self,radius):
self.radius = radius
def area(self):
return math.pi * (self.radius **2)
def perimeter(self):
return 2 math.pi (self.radius)
r = int(input("Enter Radius: "))
ans = circle(r)
print('Area is: ',round(ans.area(),2))
print('Perimeter is: ',round(ans.perimeter(),2))
class rectangle():
def init(self,length,breadth):
self.length = length
self.breadth = breadth
return (self.length) * (self.breadth)
return 2 * ((self.length) + (self.breadth))
l = int(input("Enter Length: "))
b = int(input("Enter Breadth: "))
ans = rectangle(l,b)
class triangle():
def init(self,a1,b1,a2,b2,a3,b3):
self.a1 = a1
self.b1 = b1
self.a2 = a2
self.b2 = b2
self.a3 = a3
self.b3 = b3
s1 = math.sqrt(((self.a2 - self.a1)2) + ((self.b2 - self.b1)2))
s2 = math.sqrt(((self.a3 - self.a2)2) + ((self.b3 - self.b2)2))
s3 = math.sqrt(((self.a3 - self.a1)2) + ((self.b3 - self.b1)2))
return s1 + s2 + s3
base_midpoint_x = ((self.a3 + self.a2)/2)
base_midpoint_y = ((self.b3 + self.b2)/2)
2
print(base_midpoint_x)
print(base_midpoint_y)
h = math.sqrt(((base_midpoint_x - self.a1)2) + ((base_midpoint_y - self.b1)2))
b = math.sqrt(((self.a3 - self.a2)2) + ((self.b3 - self.b2)2))
return 0.5 b h
p1 = float(input("Enter A1 Value: "))
p2 = float(input("Enter B1 Value: "))
p3 = float(input("Enter A2 Value: "))
p4 = float(input("Enter B2 Value: "))
p5 = float(input("Enter A3 Value: "))
p6 = float(input("Enter B3 Value: "))
ans = triangle(p1,p2,p3,p4,p5,p6)
print("Perimeter Of Triangle: ", ans.perimeter())
print("Area Of Triangle: ", ans.area())
import math
Circle
class circle():
def init(self,radius):
self.radius = radius
def area(self):
return math.pi * (self.radius **2)
def perimeter(self):
return 2 math.pi (self.radius)
r = int(input("Enter Radius: "))
ans = circle(r)
print('Area is: ',round(ans.area(),2))
print('Perimeter is: ',round(ans.perimeter(),2))
Rectangle
class rectangle():
def init(self,length,breadth):
self.length = length
self.breadth = breadth
def area(self):
return (self.length) * (self.breadth)
def perimeter(self):
return 2 * ((self.length) + (self.breadth))
l = int(input("Enter Length: "))
b = int(input("Enter Breadth: "))
ans = rectangle(l,b)
print('Area is: ',round(ans.area(),2))
print('Perimeter is: ',round(ans.perimeter(),2))
Triangle
class triangle():
def init(self,a1,b1,a2,b2,a3,b3):
self.a1 = a1
self.b1 = b1
self.a2 = a2
self.b2 = b2
self.a3 = a3
self.b3 = b3
def perimeter(self):
s1 = math.sqrt(((self.a2 - self.a1)2) + ((self.b2 - self.b1)2))
s2 = math.sqrt(((self.a3 - self.a2)2) + ((self.b3 - self.b2)2))
s3 = math.sqrt(((self.a3 - self.a1)2) + ((self.b3 - self.b1)2))
return s1 + s2 + s3
def area(self):
base_midpoint_x = ((self.a3 + self.a2)/2)
base_midpoint_y = ((self.b3 + self.b2)/2)
2
print(base_midpoint_x)
print(base_midpoint_y)
h = math.sqrt(((base_midpoint_x - self.a1)2) + ((base_midpoint_y - self.b1)2))
b = math.sqrt(((self.a3 - self.a2)2) + ((self.b3 - self.b2)2))
return 0.5 b h
p1 = float(input("Enter A1 Value: "))
p2 = float(input("Enter B1 Value: "))
p3 = float(input("Enter A2 Value: "))
p4 = float(input("Enter B2 Value: "))
p5 = float(input("Enter A3 Value: "))
p6 = float(input("Enter B3 Value: "))
ans = triangle(p1,p2,p3,p4,p5,p6)
print("Perimeter Of Triangle: ", ans.perimeter())
print("Area Of Triangle: ", ans.area())