Write a function to obtain sum n terms of the following series for any positive integer
value of X
1+x/1!+x2/2!+x3/3!+…
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(x, n): sum = 0 for i in range(n): sum = sum + power(x, i) / factorial(i) print(sum) n = int(input('Enter the number of terms: ')) x = int(input('Enter the value of x: ')) printSeries(x, n)
Output:
Enter the number of terms: 3
Enter the value of x: 2
5.0