Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. def is_divisible(x, y):
  2. if x % y == 0:
  3. return True
  4. else:
  5. return False
  6.  
  7. def is_power(a, b):
  8. if b == 1:
  9. return True
  10. if a == b:
  11. return True
  12. if is_divisible(a,b):
  13. x = is_power(b / a, b)
  14. return x
  15. else:
  16. return a == 1
  17.  
  18.  
  19. # check for accuracy
  20. print("is_power(10, 2) returns: ", is_power(10, 2))
  21. print("is_power(27, 3) returns: ", is_power(27, 3))
  22. print("is_power(1, 1) returns: ", is_power(1, 1))
  23. print("is_power(10, 1) returns: ", is_power(10, 1))
  24. print("is_power(3, 3) returns: ", is_power(3, 3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement