Skip to content

Instantly share code, notes, and snippets.

@hackintoshrao
Last active May 23, 2018 12:30
Show Gist options
  • Save hackintoshrao/cdb5d993d98867b1592bcb6c0e9f9b5d to your computer and use it in GitHub Desktop.
Save hackintoshrao/cdb5d993d98867b1592bcb6c0e9f9b5d to your computer and use it in GitHub Desktop.
find power by using recursion
def power(x, n):
"""
Compute the value x n for integer n
"""
if n == 0:
return 1
else:
partial = power(x, n // 2)
result = partial * partial
if n % 2 == 1:
result *= x
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment