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

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 else: 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)

Output

Enter a Number:2

Enter Power:4

2 raised to the power 4 = 16

You will also like also:

### Python Recursion With Example Recursive Function

- C Program Sum of One to N by Recursion
- C Program Sum of Digits by Recursion
- C Program Reverse Number by Recursion
- C Program Fibonacci Series by Recursion
- C Program Power By Recursion
- C Program Find Factorial by Recursion
- C Program Quick Sort
- C Program Merge Sort

- Using Recursion in Java Find Factorial of Number
- Recursion in Java Explained With Examples
- Program Factorial by Loop and Recursion Versions

98 total views, 2 views today