Part of the series

Several example codes

~2 min read • Updated Oct 12, 2025

Program Overview

This Python program reads two integers g and n and computes the result of a complex series involving factorials, powers, and algebraic fractions.
The series consists of seven terms, each combining factorial and exponential expressions.


Python Code:


import math

def compute_series(x: float, n: int) -> float:
    terms = []

    t1 = math.factorial(n) * (x ** n / math.factorial(1))
    t2 = math.factorial(n - 1) * (x ** (n - 1) / (1 - 1 / x))
    t3 = math.factorial(n + 1) * (x ** (n + 1) / (1 + 1 / x))
    t4 = math.factorial(n - 2) * (x ** (n - 2) / (2 - 2 / x))
    t5 = math.factorial(n + 2) * (x ** (n + 2) / (2 + 2 / x))
    t6 = math.factorial(n - 3) * (x ** (n - 3) / (3 - 3 / x))
    t7 = math.factorial(n + 3) * (x ** (n + 3) / (3 + 3 / x))

    return sum([t1, t2, t3, t4, t5, t6, t7])

# Read inputs from user
x = float(input("Enter value for g: "))
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: 10568.5714

Written & researched by Dr. Shahin Siami