forked from exercism/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
30 lines (24 loc) · 711 Bytes
/
example.py
File metadata and controls
30 lines (24 loc) · 711 Bytes
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
class TriangleError(Exception):
pass
class Triangle(object):
def __init__(self, x, y, z):
self.sides = (x, y, z)
if self._invalid_lengths() or self._violates_inequality():
raise TriangleError
def _invalid_lengths(self):
return any([side <= 0 for side in self.sides])
def _violates_inequality(self):
x, y, z = self.sides
return any([
x + y <= z,
x + z <= y,
y + z <= x,
])
def kind(self):
distinct = len(set(self.sides))
if distinct == 1:
return 'equilateral'
elif distinct == 2:
return 'isosceles'
else:
return 'scalene'