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 Krzysztof.Sawarzynski
import math
def isTriangle(*args):
if len(args) != 3:
return False
if args[0] + args[1] <= args[2]:
return False
if args[1] + args[2] <= args[0]:
return False
if args[2] + args[0] <= args[1]:
return False
return True
def countAngle(*args):
if len(args) != 3:
raise Exception('func countAngle need three arguments!')
return int(round(math.degrees(math.acos((args[0]**2 + args[2]**2 - args[1]**2)/(2 * args[0] * args[2])))))
def checkio(a, b, c):
result = [0, 0, 0]
if isTriangle(a, b, c) == False:
return result
result[0] = countAngle(a, b, c)
result[1] = countAngle(b, c, a)
result[2] = countAngle(c, a, b)
result.sort()
return result
#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"
Jan. 15, 2017