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

24th Dec 2020, 8:48 AM
Mitta Mukesh Kumar
Mitta Mukesh Kumar - avatar
3 odpowiedzi
+ 1
power(2, 3) = 2^3 = 2 * 2 * 2 = 8
24th Dec 2020, 9:05 AM
Sergey
Sergey - avatar
+ 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
24th Dec 2020, 10:30 AM
Yahya Bey
Yahya Bey - avatar
- 1
You're trying to get the power right? 3rd power of 2 is 8. 2 * 2 * 2 = 8
24th Dec 2020, 9:08 AM
Slick
Slick - avatar