Find other two sides and angles of a right angle triangle | Python 3 program to print all sides and angles of right angle triangle given one side ; Function to find angle A Angle in front of side a ; applied cosine rule ; convert into degrees ; Function to find angle B Angle in front of side b ; applied cosine rule ; convert into degrees and return ; Function to print all angles of the right angled triangle ; for calculate angle A ; for calculate angle B ; Function to find other two sides of the right angled triangle ; if n is odd ; case of n = 1 handled separately ; case of n = 2 handled separately ; Print angles of the triangle ; Driver Code
import math NEW_LINE PI = 3.1415926535 NEW_LINE def findAnglesA ( a , b , c ) : NEW_LINE INDENT A = math . acos ( ( b * b + c * c - a * a ) / ( 2 * b * c ) ) NEW_LINE return A * 180 / PI NEW_LINE DEDENT def findAnglesB ( a , b , c ) : NEW_LINE INDENT B = math . acos ( ( a * a + c * c - b * b ) / ( 2 * a * c ) ) NEW_LINE return B * 180 / PI NEW_LINE DEDENT def printAngles ( a , b , c ) : NEW_LINE INDENT x = a NEW_LINE y = b NEW_LINE z = c NEW_LINE A = findAnglesA ( x , y , z ) NEW_LINE B = findAnglesB ( x , y , z ) NEW_LINE print ( " Angles ▁ are ▁ A ▁ = ▁ " , A , " , ▁ B ▁ = ▁ " , B , " , ▁ C ▁ = ▁ " , "90 ▁ " ) NEW_LINE DEDENT def printOtherSides ( n ) : NEW_LINE INDENT if ( n & 1 ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT print ( " - 1" ) NEW_LINE DEDENT else : NEW_LINE INDENT b = ( n * n - 1 ) // 2 NEW_LINE c = ( n * n + 1 ) // 2 NEW_LINE print ( " Side ▁ b ▁ = ▁ " , b , " ▁ Side ▁ c ▁ = ▁ " , c ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if ( n == 2 ) : NEW_LINE INDENT print ( " - 1" ) NEW_LINE DEDENT else : NEW_LINE INDENT b = n * n // 4 - 1 ; NEW_LINE c = n * n // 4 + 1 ; NEW_LINE print ( " Side ▁ b ▁ = ▁ " , b , " , ▁ Side ▁ c ▁ = ▁ " , c ) NEW_LINE DEDENT DEDENT printAngles ( n , b , c ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = 12 NEW_LINE printOtherSides ( a ) NEW_LINE DEDENT