-
Notifications
You must be signed in to change notification settings - Fork 25
/
geometry.py
67 lines (30 loc) · 1.07 KB
/
geometry.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class Triangle:
"""A simple class to calculate measurements of a triangle"""
def __init__(self, a, b, c, h):
self.a, self.b, self.c, self.h = a, b, c ,h
def area(self):
"""Calculate the triangle's area"""
return float(self.b)*float(self.h)/2.
def perimeter(self):
"""Calculate the triangle's perimeter"""
return self.a+self.b+self.c
class Square:
"""A simple class to calculate measurements of a square"""
def __init__(self, l):
self.l = l
def area(self):
"""Calculate the square's area"""
return self.l**2
def perimeter(self):
"""Calculate the square's perimeter"""
return self.l*4.
class Rectangle:
"""A simple class to calculate measurements of a rectangle"""
def __init__(self, b, h):
self.b, self.h = b, h
def area(self):
"""Calculate the rectangle's area"""
return self.b*self.h
def perimeter(self):
"""Calculate the rectangle's perimeter"""
return 2.*(self.b+self.h)