Informatics Practices
WAP to print the sum of the series 1 - x2/4! + x3/6! - x4/8! + x5/10! …………… xn/(2n)! — exponential series.
Python Control Flow
2 Likes
Answer
x = int(input("Enter x: "))
n = int(input("Enter n: "))
sum_series = 1
sign = -1
for i in range(2, n + 1):
fact = 1
for j in range(1, 2 * i + 1):
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.8444444444444444
Answered By
3 Likes
Related Questions
Write a function to display prime numbers below 30.
WAP to print the sum of the series 1 - x1/2! + x2/3! - x3/4! …………… xn/(n + 1)! — exponential series.
WAP to display the sum of the given series:
Sum = 1 + (1 + 2) + (1 + 2 + 3) + (1 + 2 + 3…..n)
WAP to print the following pattern:
* * * * * * * * * * * * * * *