This Python program reads two values x and n and computes the result of the following series:
1 + ∑ [(n(n-1)...(n-k+1) · x^k) / k!] for k from 1 to n
It uses a helper function to compute the descending product and standard factorial for the denominator.
import math
def descending_product(n: int, k: int) -> int:
result = 1
for i in range(k):
result *= (n - i)
return result
def compute_series(x: float, n: int) -> float:
total = 1.0
for k in range(1, n + 1):
numerator = descending_product(n, k) * (x ** k)
denominator = math.factorial(k)
total += numerator / denominator
return total
# 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:.6f}")
Series result is: 21.000000