Part of the series

Several example codes

~2 min read • Updated Oct 12, 2025

Program Overview

This Python program reads two values x and n and computes the result of the following algebraic series:
x⁰ / -n + x¹·1ⁿ⁻¹ / -(n-1) + xⁿ⁻¹·(n-1) / -1 + xⁿ·(n+1)² / 1 + xⁿ⁺¹·(1+1)² / 2 + x²ⁿ⁻¹·(2n-1)ⁿ / n
Each term combines exponentiation, multiplication, and division.


Python Code:


def compute_series(x: float, n: int) -> float:
    try:
        term1 = x**0 / (-n)
        term2 = x**1 * (1**(n - 1)) / (-(n - 1))
        term3 = x**(n - 1) * ((n - 1)**1) / (-1)
        term4 = x**n * ((n + 1)**2) / 1
        term5 = x**(n + 1) * ((1 + 1)**2) / 2
        term6 = x**(2 * n - 1) * ((2 * n - 1)**n) / n

        return term1 + term2 + term3 + term4 + term5 + term6
    except ZeroDivisionError:
        return float('inf')

# Read inputs from user
x = float(input("Enter value for x: "))
n = int(input("Enter value for n: "))

result = compute_series(x, n)
print(f"Series result is: {result:.4f}")

Sample Output (input: x = 2, n = 3):


Series result is: 10579.8333

Written & researched by Dr. Shahin Siami