Programming Examples

Python Function to Compute the Sum of n Terms of the Following Series


Write a Function to Compute the Sum of n Terms of the Following Series.

Series: X + X^4 / 4! + X^6 / 6! + X^8 / 8! + ... for any positive integer value of X.

import math
def series_sum(x, n):
    total = x  # First term is X
    power = 4  # Starting power for next term
    for i in range(1, n):
        total += (x ** power) / math.factorial(power)
        power += 2  # Increase power by 2 each time
    return total
x = int(input("Enter value of X: "))
n = int(input("Enter number of terms: "))
result = series_sum(x, n)
print("Sum of the series:", result)

Output

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad