17.8.1: Writing a recursive math function. Write code to complete raise_to_power(). Note: This example is for practicing recursion; a non-recursive function, or using the built-in function math.pow(), would be more common.

Respuesta :

Answer:

The recursion function is as follows:

def raise_to_power(num, power):

if power == 0:

 return 1

elif power == 1:

 return num

else:

 return (num*raise_to_power(num, power-1))

Explanation:

This defines the function

def raise_to_power(num, power):

If power is 0, this returns 1

if power == 0:

 return 1

If power is 1, this returns num

elif power == 1:

 return num

If otherwise, it calculates the power recursively

else:

 return (num*raise_to_power(num, power-1))