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 Rafal.U
def checkio(a, b, c):
try:
from math import acos, degrees # importowanie z biblioteki math funkcji acos i degrees
x = round(degrees(acos((c**2 - b**2 - a**2)/(-2.0 * a * b)))) # wyliczenie ze wzoru na podstawie długości boków trójkąta jego kątów
y = round(degrees(acos((b**2 - a**2 - c**2)/(-2.0 * a * c))))
z = round(degrees(acos((a**2 - c**2 - b**2)/(-2.0 * c * b))))
lista = [] # deklaracja pustej listy
lista.append(x) # dodanie do listy wartosci wyliczonych kątów trójkata x, y, z
lista.append(y)
lista.append(z)
lista.sort() # posortowanie elementów listy
if x == 0 or y == 0 or z == 0: # żaden z kątów nigdy nie może być zerowy, gdy pojawi sie taka sytuacje program zwraca [0, 0, 0]
return [0, 0, 0]
return lista # program zwraca posortowaną listę wyliczonych wartości trójkąta, gdy długośc boków trójkąta podana na wejście jest ok
except ValueError: # zwraca [0, 0, 0] gdy wystapi blad wartosci, gdy z podanych dlugosci boków nie da się utworzyc trójkąta i jest blad
return [0, 0, 0] # przy wyliczaniu kątów
#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"
Dec. 10, 2016