Сагура Николай, 392, сев. филиал TrianglesCmp 5834
Тулебаев Адильхан, 416 группа TrianglesCmp 6112
f1from math import isclose, sqrtf1from math import isclose, sqrt
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 = (float(a), float(b), float(c))6        self.a, self.b, self.c = (float(a), float(b), float(c))
7        if self.a <= 0 or self.b <= 0 or self.c <= 0 or (self.a + self.b7        if self.a <= 0 or self.b <= 0 or self.c <= 0 or (self.a + self.b
> <= self.c) or (self.a + self.c <= self.b) or (self.b + self.c <= self.a> <= self.c) or (self.a + self.c <= self.b) or (self.b + self.c <= self.a
>):>):
n8            self.valid = Falsen8            self.empty = True
9        else:9        else:
n10            self.valid = Truen10            self.empty = False
1111
12    def __bool__(self):12    def __bool__(self):
n13        return self.validn13        return not self.empty
1414
15    def __abs__(self):15    def __abs__(self):
n16        if not self:n16        if self.empty:
17            return 0.017            return 0.0
18        p = (self.a + self.b + self.c) / 218        p = (self.a + self.b + self.c) / 2
19        return sqrt(p * (p - self.a) * (p - self.b) * (p - self.c))19        return sqrt(p * (p - self.a) * (p - self.b) * (p - self.c))
2020
21    def __eq__(self, other):21    def __eq__(self, other):
22        if not isinstance(other, Triangle):22        if not isinstance(other, Triangle):
23            return NotImplemented23            return NotImplemented
24        sides1 = sorted([self.a, self.b, self.c])24        sides1 = sorted([self.a, self.b, self.c])
25        sides2 = sorted([other.a, other.b, other.c])25        sides2 = sorted([other.a, other.b, other.c])
26        return all((isclose(x, y) for x, y in zip(sides1, sides2)))26        return all((isclose(x, y) for x, y in zip(sides1, sides2)))
2727
28    def __lt__(self, other):28    def __lt__(self, other):
29        return abs(self) < abs(other)29        return abs(self) < abs(other)
3030
31    def __le__(self, other):31    def __le__(self, other):
32        return abs(self) <= abs(other)32        return abs(self) <= abs(other)
3333
34    def __gt__(self, other):34    def __gt__(self, other):
35        return abs(self) > abs(other)35        return abs(self) > abs(other)
3636
37    def __ge__(self, other):37    def __ge__(self, other):
38        return abs(self) >= abs(other)38        return abs(self) >= abs(other)
3939
40    def __str__(self):40    def __str__(self):
41        return f'{self.a}:{self.b}:{self.c}'41        return f'{self.a}:{self.b}:{self.c}'
t42'tri = Triangle(3, 4, 5), Triangle(5, 4, 3), Triangle(7, 1, 1), Trianglet
>(5, 5, 5), Triangle(7, 4, 4)\nfor a, b in zip(tri[:-1], tri[1:]):\n    p 
>rint(a if a else b)\n    print(f"{a}={abs(a):.2f} {b}={abs(b):.2f}")\n   
>  print(a == b)\n    print(a >= b)\n    print(a < b)' 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op