fork download
  1. def is_power_of(number, base):
  2. # Base case: when number is smaller than base.
  3. if number < base:
  4. # If number is equal to 1, it's a power (base**0).
  5. if number == 1:
  6. return True
  7. return False
  8.  
  9. # Recursive case: keep dividing number by base.
  10. return is_power_of(number/base, base)
  11.  
  12. print(is_power_of(8,2)) # Should be True
  13. print(is_power_of(64,4)) # Should be True
  14. print(is_power_of(70,10)) # Should be False
Success #stdin #stdout 0.02s 9100KB
stdin
Standard input is empty
stdout
True
True
False