0
python-functional programming
Module 7 Quiz What is the result of this code? def power(x, y): if y == 0: return 1 else: return x * power(x, y-1) print(power(2, 3)) i think its 4 but the answer is 8 how? where power(x,y-1)==2,so 2**2==4
3 Answers
+ 1
power(2, 3) = 2^3 = 2 * 2 * 2 = 8
+ 1
Isn't it 2*power(2,2)
Power(2,2) = 2*power(2,1)
So power(2,2) = 4
So 2 * 4 is 8
- 1
You're trying to get the power right? 3rd power of 2 is 8. 2 * 2 * 2 = 8