Part of the series

Several example codes

~1 min read • Updated Oct 11, 2025

Program Overview

This Python program reads two values from the user:
- A floating-point number (base)
- An integer (exponent), which can be positive or negative
It sends both values to a method that calculates the base raised to the power of the exponent.
The result is returned and displayed.


Python Code:


def power(base: float, exponent: int) -> float:
    return base ** exponent

# Run the program
base = float(input("Enter the base (decimal number): "))
exponent = int(input("Enter the exponent (positive or negative integer): "))

result = power(base, exponent)
print(f"{base} raised to the power of {exponent} is: {result:.4f}")

Sample Output (input: base = 2.5, exponent = -2):


2.5 raised to the power of -2 is: 0.1600

Step-by-Step Explanation:

- The program reads a decimal base and an integer exponent from the user
- It sends both to a method called power
- The method uses the ** operator to compute the result
- The result is returned to the main program and printed with four decimal places


Written & researched by Dr. Shahin Siami