Part of the series

Several example codes

~1 min read • Updated Oct 12, 2025

Program Overview

This Python program reads three values x, a, and n from the user and computes the result of a mathematical expression.
The formula may involve exponentiation, division, and summation, implemented via a loop or recursion.


Python Code (general example):


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

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

result = compute_expression(x, a, n)
print(f"Result of the expression is: {result:.4f}")

Sample Output (input: x = 2, a = 1, n = 3):


Result of the expression is: 1131.1111

Written & researched by Dr. Shahin Siami