Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Angles of a Triangle by zgub4
import math
def checkio(a, b, c):
if a + b <= c or a + c <= b or b + c <= a:
return [0, 0, 0]
cos_a = calculate_cos(a, b, c)
cos_b = calculate_cos(b, a, c)
cos_c = calculate_cos(c, a, b)
return sorted([round(math.degrees(math.acos(cos_a))),
round(math.degrees(math.acos(cos_b))),
round(math.degrees(math.acos(cos_c)))])
def calculate_cos(target, first_side, second_side):
return (first_side ** 2 + second_side ** 2 - target ** 2) / (2.0 * first_side * second_side)
if __name__ == '__main__':
# assert checkio(4, 4, 4) == [60, 60, 60], "All sides are equal"
assert checkio(3, 4, 5) == [37, 53, 90], "Egyptian triangle"
assert checkio(2, 2, 5) == [0, 0, 0], "It's can not be a triangle"
Oct. 21, 2017