MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / power

Function power

Python/5 recusrion problems.py:62–69  ·  view source on GitHub ↗
(base,exp)

Source from the content-addressed store, hash-verified

60# 5..TO FIND THE POWER OF A NUMBER
61
62def power(base,exp):
63 assert exp>=0 and int(exp)==exp , "power can only be positive integers"
64 if(exp==0):
65 return 1
66 if(exp==1):
67 return base
68 else:
69 return base*power(base,exp-1)
70
71print(power(2,5))

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected