Городецкая Агнесса Алексеевна 418 TrianglesCmp 5868
action22k TrianglesCmp 6167
n1from math import isclose, sqrtn1from math import sqrt, isclose
22
3class Triangle:3class Triangle:
44
5    def __init__(self, a, b, c):5    def __init__(self, a, b, c):
6        self.a, self.b, self.c = map(float, (a, b, c))6        self.a, self.b, self.c = map(float, (a, b, c))
7        self.valid = self.a > 0 and self.b > 0 and (self.c > 0) and (sel7        self.valid = self.a > 0 and self.b > 0 and (self.c > 0) and (sel
>f.a + self.b > self.c) and (self.a + self.c > self.b) and (self.b + self>f.a + self.b > self.c) and (self.a + self.c > self.b) and (self.b + self
>.c > self.a)>.c > self.a)
88
9    def __bool__(self):9    def __bool__(self):
10        return self.valid10        return self.valid
1111
12    def __abs__(self):12    def __abs__(self):
n13        if not self.valid:n13        if not self:
14            return 0.014            return 0.0
t15        s = (self.a + self.b + self.c) / 2t15        p = (self.a + self.b + self.c) / 2
16        return sqrt(s * (s - self.a) * (s - self.b) * (s - self.c))16        return sqrt(p * (p - self.a) * (p - self.b) * (p - self.c))
1717
18    def __eq__(self, other):18    def __eq__(self, other):
19        if not isinstance(other, Triangle):19        if not isinstance(other, Triangle):
20            return NotImplemented20            return NotImplemented
21        return all((isclose(x, y) for x, y in zip(sorted((self.a, self.b21        return all((isclose(x, y) for x, y in zip(sorted((self.a, self.b
>, self.c)), sorted((other.a, other.b, other.c)))))>, self.c)), sorted((other.a, other.b, other.c)))))
2222
23    def __lt__(self, other):23    def __lt__(self, other):
24        return abs(self) < abs(other)24        return abs(self) < abs(other)
2525
26    def __le__(self, other):26    def __le__(self, other):
27        return abs(self) <= abs(other)27        return abs(self) <= abs(other)
2828
29    def __gt__(self, other):29    def __gt__(self, other):
30        return abs(self) > abs(other)30        return abs(self) > abs(other)
3131
32    def __ge__(self, other):32    def __ge__(self, other):
33        return abs(self) >= abs(other)33        return abs(self) >= abs(other)
3434
35    def __str__(self):35    def __str__(self):
36        return f'{self.a}:{self.b}:{self.c}'36        return f'{self.a}:{self.b}:{self.c}'
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op