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
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}")
Series result is: 2.083333