Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def explicit_exponentiation(a, b):
- output = 1
- top = b
- if (b < 0):
- top *= -1
- for i in range(top):
- output *= a
- if b < 0:
- return 1/output
- else:
- return output
- def recursive_exponentiation(a, b):
- if b == 0:
- return 1
- else:
- if b < 0:
- return (1/a)*recursive_exponentiation(a, b+1)
- else:
- return a * recursive_exponentiation(a, b-1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement