Advertisement
MoSBanapple

Untitled

Dec 1st, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. def explicit_exponentiation(a, b):
  2.     output = 1
  3.     top = b
  4.     if (b < 0):
  5.         top *= -1
  6.     for i in range(top):
  7.         output *= a
  8.     if b < 0:
  9.         return 1/output
  10.     else:
  11.         return output
  12.  
  13.  
  14.  
  15. def recursive_exponentiation(a, b):
  16.    if b == 0:
  17.        return 1
  18.    else:
  19.        if b < 0:
  20.            return (1/a)*recursive_exponentiation(a, b+1)
  21.        else:
  22.            return a * recursive_exponentiation(a, b-1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement