Python Question Write a function called power It is passed 2
Python Question:
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 module or any of the names (functions) in the math module.
The solution must be Recursive
For example:
>>> power(2,3)
8
>>> power(5,2)
25
>>> power(3,0)
1
Solution
=========Python Program========
def power(base, exp):
if (exp == 0):
return 1
else:
return base * power(base, exp - 1)
print power(2,3)
print power(5,2)
print power(3,0)
