Skip to content

Recursion · routine

Fast power

Write power(x, n) returning x to the power n (a whole number n >= 0) with recursion — without ** or pow.

x^n is (x^(n/2))² when n is even: one recursive call halves the problem.

Run adds print(power(2, 10)) after your code, to try it.

Stuck on the idea rather than the code? The Recursion that halves, and recursion that branches lesson walks through it.