0
return x * power(x, y-1)?
def power(x, y): if y == 0: return 1 else: return x * power (x, y-1) print(power(2, 3)) Output: 8 #y is not equal to 0, so I run else # return 2 * power(2, 3-1) __evaluates to__ 2 * power (2, 2) #How did they get print(power(2, 3))? Was I just to ignore the top portion of the code? #Even then, shouldn't it say something like 2 *= 3? Where was what I was supposed to do with the (2, 3) defined? Thanks for any help;)).
1 Answer
0
power(2, 3) # y == 3
== 2 * power(2, 3-1) == 2 * power(2 , 2) # y == 2
== 2 * 2 * power(2, 2-1) == 4 * power(2, 1) # y == 1
== 4 * 2 * power(2, 1-1) == 8 * power(2, 0) # y == 0
== 8 * 1 == 8.