Python Power Recursive Function

By | December 4, 2022

Python Power Recursive Function – Write a Python program that uses recursion concept to calculate a number N raised to the power P.

Python Power Recursive Function


Python Recursive Function Power

# Write a Recursive Function power_recursive(n,p)
# to calculate n raised to power p.

# define function
def power(n, p):
    if p == 0:
        return 1
        return n * power(n, p-1);
# main

#input number and power
num = int(input("Enter a Number:"))
p = int(input("Enter Power:"))
# call the function
res =power(num,p)
# display result
print(num," raised to the power ",p," = ",res)


Enter a Number:2
Enter Power:4
2 raised to the power 4 = 16

Reursive function power in Python

You will also like also:

Python Recursion With Example Recursive Function 

 98 total views,  2 views today

Leave a Reply

Your email address will not be published. Required fields are marked *