This Python program reads two values x and n from the user and computes the sum of the following series:
Γ(x, n) = x¹/1! + x²/2! + x³/3! + ... + xⁿ/n!
This is a truncated exponential series used to approximate e^x, excluding the zeroth term.
def factorial(k: int) -> int:
result = 1
for i in range(2, k + 1):
result *= i
return result
def gamma_series(x: float, n: int) -> float:
total = 0.0
for k in range(1, n + 1):
total += (x ** k) / factorial(k)
return total
# Read inputs from user
x = float(input("Enter value for x: "))
n = int(input("Enter number of terms n: "))
result = gamma_series(x, n)
print(f"Γ(x, n) = {result:.6f}")
Γ(x, n) = 5.000000