Write a function to compute the sum

 Write a function to compute the sum of the first k terms of the series expansion for the sine function (-1)” (2n +1)! 2n +1 sin(x) = TL 0 The first three terms (k = 3) of the expansion are: 1 1 73 + sin(x) = 2 ਕ 5 Function specification: Your function should be called series sine(x, k) where x is the argument of the sine function and a total of k number of terms from the expansion should be summed. You are not allowed to import a factorial function (or anything else) from any of Python’s libraries – you don’t need it and it’ll slow down your function significantly! For example: Test Result import numpy as np 1.571 # Uses your series_sine to calculate sin(pi/2) with 1 to 3 iterations. 0.925 ans_literation = series_sine (np.pi/2, 1) 1.005 print(f'{ans_literation:.3f}’) ans_2iterations – series_sine (np.pi/2, 2) print(f'{ans_2iterations:.3f}’) ans_3iterations = series_sine (np.pi/2, 3) print(f'{ans_3iterations:.3f}’) Correct! ans = series_sine (1.6, 11) if abs (ans – 0.9996) < le-4: print("Correct!") else: print("Wrong answer.") print(f"Your answer was: {ans}")
 

Tags: No tags