Program to find the value of tan ( nÎ ˜ ) | Python3 program to find the value of cos ( n - theta ) ; Function to calculate the binomial coefficient upto 15 ; use simple DP to find coefficient ; Function to find the value of cos ( n - theta ) ; store required answer ; use to toggle sign in sequence . ; calculate numerator ; calculate denominator ; Driver code
import math NEW_LINE MAX = 16 NEW_LINE nCr = [ [ 0 for i in range ( MAX ) ] for i in range ( MAX ) ] NEW_LINE def binomial ( ) : NEW_LINE INDENT for i in range ( MAX ) : NEW_LINE INDENT for j in range ( 0 , i + 1 ) : NEW_LINE INDENT if j == 0 or j == i : NEW_LINE INDENT nCr [ i ] [ j ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT nCr [ i ] [ j ] = nCr [ i - 1 ] [ j ] + nCr [ i - 1 ] [ j - 1 ] NEW_LINE DEDENT DEDENT DEDENT DEDENT def findTanNTheta ( tanTheta , n ) : NEW_LINE INDENT numerator = 0 NEW_LINE denominator = 1 NEW_LINE ans = 0 NEW_LINE toggle = 1 NEW_LINE for i in range ( 1 , n + 1 , 2 ) : NEW_LINE INDENT numerator = ( numerator + nCr [ n ] [ i ] * ( tanTheta ** ( i ) ) * toggle ) NEW_LINE toggle = toggle * - 1 NEW_LINE DEDENT toggle = - 1 NEW_LINE for i in range ( 2 , n + 1 , 2 ) : NEW_LINE INDENT numerator = ( numerator + nCr [ n ] [ i ] * ( tanTheta ** i ) * toggle ) NEW_LINE toggle = toggle * - 1 NEW_LINE DEDENT ans = numerator / denominator NEW_LINE return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT binomial ( ) NEW_LINE tanTheta = 0.3 NEW_LINE n = 10 NEW_LINE print ( findTanNTheta ( tanTheta , n ) ) NEW_LINE DEDENT