Informatics Practices
WAP to print the sum of the series 1 - x1/2! + x2/3! - x3/4! …………… xn/(n + 1)! — exponential series.
Answer
x = int(input("Enter x: "))
n = int(input("Enter n: "))
sum_series = 1
sign = -1
for i in range(1, n + 1):
fact = 1
for j in range(1, i + 2):
fact *= j
term = sign * (x ** i) / fact
sum_series += term
sign *= -1
print("Sum =", sum_series)Output
Enter x: 2
Enter n: 3
Sum = 0.3333333333333333
Related Questions
Write a Python program to compute sum of digits of a given number.
Write a function to display prime numbers below 30.
WAP to print the sum of the series 1 - x2/4! + x3/6! - x4/8! + x5/10! …………… xn/(2n)! — exponential series.
WAP to display the sum of the given series:
Sum = 1 + (1 + 2) + (1 + 2 + 3) + (1 + 2 + 3…..n)