Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
OOP solution solution in Clear category for The Angles of a Triangle by swagg010164
from typing import List
from math import acos, degrees
from dataclasses import dataclass
def round_decorator(func):
def wrapper(*args, **kwargs):
res = func(*args, **kwargs)
if res - int(res) >= 0.5:
return int(res) + 1
return int(res)
return wrapper
@dataclass
class Trianle:
a: int
b: int
c: int
@property
def is_valid(self):
return self.a + self.b > self.c and \
self.a + self.c > self.b and \
self.b + self.c > self.a
def get_angles(self):
first_angle = self.__get_first_angle()
second_angle = self.__get_second_angle()
ans = [first_angle, second_angle, 180 - first_angle - second_angle]
ans.sort()
return ans
@round_decorator
def __get_first_angle(self):
return degrees(acos((self.b ** 2 + self.c ** 2 - self.a ** 2) / (2 * self.b * self.c)))
@round_decorator
def __get_second_angle(self):
return degrees(acos((self.b ** 2 + self.a ** 2 - self.c ** 2) / (2 * self.b * self.a)))
def checkio(a: int, b: int, c: int) -> List[int]:
triangle = Trianle(a, b, c)
print(triangle.is_valid)
if not triangle.is_valid:
return [0, 0, 0]
return triangle.get_angles()
Aug. 12, 2020
Comments: