This Python program reads three integers x, n, and k from the user, and computes the value of the expression:
\[
F(x,n,k) = \frac{x^2 + x^3 + \dots + x^n}{k}
\]
The numerator is the sum of powers of x from 2 to n, and the denominator is simply k.
# Read x, n, and k from user
x = int(input("Enter value for x: "))
n = int(input("Enter value for n: "))
k = int(input("Enter value for k: "))
# Compute numerator: sum of x^2 to x^n
numerator = 0
for j in range(2, n + 1):
numerator += x ** j
# Compute denominator: sum of 1 repeated k times = k
denominator = k if k != 0 else 1 # Avoid division by zero
# Final result
F = numerator / denominator
print("F(x, n, k) =", F)
Enter value for x: 2
Enter value for n: 4
Enter value for k: 3
F(x, n, k) = 6.0
- The loop starts from 2 to n to exclude x¹ from the numerator
- The denominator is simply k, since ∑ₖ₌₁¹ = k
- A check is added to avoid division by zero if k = 0
- The final result is printed as a floating-point value