-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquadrilateral
More file actions
50 lines (39 loc) · 1.5 KB
/
quadrilateral
File metadata and controls
50 lines (39 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class Quadrilateral:
def __init__(self, init_a, init_b, init_c, init_d):
AT = [int, float]
if ((type(init_a) not in AT) or
(type(init_b) not in AT) or
(type(init_c) not in AT) or
(type(init_d) not in AT)):
raise TypeError("Bad type : side of a quadrilateral")
if ((init_a <= 0 or init_b <= 0 or init_c <= 0 or init_d <= 0) or
(init_a > init_b + init_c + init_d) or
(init_b > init_a + init_c + init_d) or
(init_c > init_a + init_b + init_d) or
(init_d > init_a + init_b + init_c)):
raise ValueError("Bad value : side of a quadrilateral")
self.a = init_a
self.b = init_b
self.c = init_c
self.d = init_d
def perimeter(self):
return (self.a + self.b + self.c + self.d)
def area(self):
s = self.perimeter() / 2
return ((s - self.a) * (s - self.b) * (s - self.c) * (s - self.d)) ** 0.5
class Square(Quadrilateral):
def __init__(self, a):
Quadrilateral.__init__(self, a, a, a, a)
def area(self):
return self.a ** 2
def get_diagonal(self):
return self.a * (2 ** 0.5)
def main():
Q = Quadrilateral(14.32, 21.54, 43.21, 17.3)
P = Q.perimeter()
A = Q.area()
print("Perimeter = %.3f Area = %.3f" % (P, A))
S = Square(10)
print("Diagonal(S):%.3f" % S.get_diagonal())
print("Perimeter of S = %.3f Area of S = %.3f" % (S.perimeter(), S.area()))
main()