Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from dataclasses import dataclass
- class TriangleNotExistException(Exception):
- def __init__(self):
- super().__init__("Triangle with this sides doesn't exist")
- @dataclass
- class Triangle:
- """Класс треугольника"""
- a: int
- b: int
- c: int
- def __post_init__(self):
- if self.a + self.b <= self.c:
- raise TriangleNotExistException
- if self.b + self.c <= self.a:
- raise TriangleNotExistException
- if self.a + self.c <= self.b:
- raise TriangleNotExistException
- @property
- def ttype(self):
- if self.a == self.b == self.c:
- return "equilateral triangle"
- if self.a == self.b or self.c == self.a or self.b == self.c:
- return "isosceles triangle"
- return "normal triangle"
- if __name__ == "__main__":
- tr1 = Triangle(2, 2, 3)
- print(tr1.ttype)
- tr2 = Triangle(1, 1, 100)
Advertisement
Add Comment
Please, Sign In to add comment