Skip to main content

Write a program to show the use of recursion in calculation of power.

#Program to show the use of recursion in calculation  of power.
#Code
#power a to b using recursion 6_4

def power(a,b):
        if b==0:
                return 1
        else:
                return a*power(a,b-1)

#_main_
print("Enter only the positive numbers below")
num=int(input("Enter base number:"))
p=int(input("raised to the power of:"))
result=power(num,p)
print(num,"raised to the power of",p,"is",result)

Output

Comments

Popular posts from this blog