2. Power of 2
In [5]:
Copied!
def power_of_2(n):
# 1. write the base case
if n == 0:
return 1
# 2. Reccurence relation
smaller_problem = power_of_2(n - 1)
bigger_problem = 2 * smaller_problem
return bigger_problem
def power_of_2(n):
# 1. write the base case
if n == 0:
return 1
# 2. Reccurence relation
smaller_problem = power_of_2(n - 1)
bigger_problem = 2 * smaller_problem
return bigger_problem
In [6]:
Copied!
power_of_2(100)
power_of_2(100)
Out[6]:
1267650600228229401496703205376
In [ ]:
Copied!