In this Python Program, we will learn how to calculate the Nth power of a number using Recursion.
Here is the code of the program to calculate the Nth power of a number without using Recursion.
# Python Program to Find the Power of a Number Using Recursion
# Define a Recursive Function
def power(base,exp):
if(exp==1):
return(base)
if(exp!=1):
return(base*power(base,exp-1))
# To Take Input From the User
number = int(input("Enter any Positive Number: "))
exponent = int(input("Enter Exponent Value: "))
print("The Result of {0} Power {1} = {2}".format(number,exponent,power(number,exponent)))
Enter any Positive Number: 5
Enter Exponent Value: 5
The Result of 5 Power 5 = 3125
Comments