Write a function to obtain sum n terms of the following series for any positive integer
value of X
X +X3 /3! +X5 /5! ! +X7 /7! + …
def power(a, b): p = 1 for i in range(1, b + 1): p = p * a return p def factorial(n): f = 1 for i in range(1, n + 1): f = f * i return f def printSeries(): sum = 0 n = int(input('Enter the number of terms: ')) x = int(input('Enter the value of x: ')) for i in range(1, 2 * n + 1, 2): sum = sum + power(x, i) / factorial(i) print(sum) printSeries()
Output :
Enter the number of terms: 3
Enter the value of x: 2
18.333333333333332