Python Program to Calculate the Power using Recursion

Python Program to Calculate the Power using Recursion

Write Python Program to Calculate the Power using Recursion

# Write Python Program to Calculate the Power using Recursion

def power(x, n):
    if n == 1:
        result = x
    else:
        result = x * power(x, n - 1)
        
    return result

x = 4
n = 3
ans = power(x, n)

print(f'{x} ^ {n} = {ans}')

Output:

4 ^ 3 = 64