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.
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}")
2.5 raised to the power of -2 is: 0.1600
- 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