PYTHON Solution must be recursive You are not allowed to use

PYTHON
Solution must be recursive. You are not allowed to use loops, or use the python \"in\" operator.


Write a function called power. It is passed 2 parameters, x and y, and returns x to power of y. You may not use ** and you may not import the math madule or any of the names(functions) in the math module.

>>> power(2,3)

8

>>> power(5,2)

25

>>> power(3,0)

1

Solution

def power(x,y):
if y == 0:
return 1
else:
return x * power(x,y-1)

PYTHON Solution must be recursive. You are not allowed to use loops, or use the python \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site