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 Adrian_W
from math import degrees, acos
def checkio(a, b, c):
if not(a+b>c and a+c>b and b+c>a):
return [0,0,0]
elif a==b and b==c:
return [60,60,60]
elif a/b==3/4 and b/c==4/5 and a/c==3/5:
return [37, 53, 90]
list=[]
list.append(degrees(acos((a*a+b*b-c*c)/(2*a*b))))#cosc
list.append(degrees(acos((c*c+b*b-a*a)/(2*c*b))))#cosa
list.append(degrees(acos((a*a+c*c-b*b)/(2*a*c))))#cosb
for i in range (0,3):
if list[i]>= int(list[i])+0.5:
list[i]= int(list[i]+1)
else:
list[i]=int(list[i])
#replace this for solution
list=sorted(list)
return list
#These "asserts" using only for self-checking and not necessary for auto-testing
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. 17, 2016