Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import division
- def power(x, n):
- if x == 0:
- return "x can't be zero."
- if n == 0:
- return 1
- if n > 0:
- return x * power(x, n - 1)
- if n < 0:
- return 1 / power(x, -n)
- print power(3, 3)
- print power(2, -4)
- print power(2, 0)
- print power(0, -2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement