Part of the series

Several example codes

~1 min read • Updated Oct 13, 2025

Program Overview

This Python program reads an integer n and a value x, and computes the result of the following series:
∑ [(n - k) / (k · x)] for k from 1 to n - 1


Python Code:


def compute_series(n: int, x: float) -> float:
    total = 0.0
    for k in range(1, n):
        term = (n - k) / (k * x)
        total += term
    return total

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

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

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


Series result is: 2.083333

Written & researched by Dr. Shahin Siami