Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_divisible(x, y):
- if x % y == 0:
- return True
- else:
- return False
- def is_power(a, b):
- if b == 1:
- return True
- if a == b:
- return True
- if is_divisible(a,b):
- x = is_power(b / a, b)
- return x
- else:
- return a == 1
- # check for accuracy
- print("is_power(10, 2) returns: ", is_power(10, 2))
- print("is_power(27, 3) returns: ", is_power(27, 3))
- print("is_power(1, 1) returns: ", is_power(1, 1))
- print("is_power(10, 1) returns: ", is_power(10, 1))
- print("is_power(3, 3) returns: ", is_power(3, 3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement