Welcome to Westonci.ca, the ultimate question and answer platform. Get expert answers to your questions quickly and accurately. Join our platform to connect with experts ready to provide precise answers to your questions in different areas. Join our Q&A platform to connect with experts dedicated to providing accurate answers to your questions in various fields.

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.

Sagot :

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