Python Program To Calculate Power Using Recursive Function

In this program, we read value of base and exponent from user and then we calculate baseexponent using recursive function power().

This Python program calculates base power exponent using recursive function.

Python Source Code

# power calculation using recursion

# Recursive function definition
def power(x,n):
    if n==0:
        return 1
        return x * power(x, n-1)

# Reading base and exponent 
base = float(input("Enter value of base: "))
exponent = int(input("Enter value of exponent: "))

# Function call
result = power(base, exponent)

# Displaying result
print("Result is:", result)


Enter value of base: 2
Enter value of exponent: 3
Result is: 8.0