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 lukas.linhart
from math import acos, degrees
def angle(*sides):
"""
Returns angle as int computed from sides of a triangle.
"""
a, b, c = sides
angle = round(degrees(acos((b**2 + c**2 - a**2)/(2*b*c))))
if not angle:
raise ValueError
else:
return angle
def checkio(*sides):
"""
Returns sorted list of angles of a triangle from its sides,
or all zeros for invalid triangles.
"""
combos = (sides[x:] + sides[:x] for x in range(3))
try:
return sorted(angle(*sides) for sides in combos)
except ValueError:
return [0, 0, 0]
March 4, 2015