Question: Which of these functions is a recursive program that correctly calculates the power of a number raised to another ( a ^ b ) ?

Which of these functions is a recursive program that correctly calculates the power of a number raised to another (a^b)?
a.
def power(a,b):
if b ==1:
return a
else:
return a*power(b-1,a)
b.
def power(a,b):
if b ==1:
return a
else:
return a*power(a,b-1)
c.
def power(a,b):
if b ==1:
return a
else:
return a**power(a,b-1)
d.
None of these
e.
def power(a,b):
if b ==1:
return a
else:
return a**power(b-1,a)
f.
def power(a,b):
sm =1
for i in range(b):
sm*=a
return sm

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!