def is_power(a,b):
   '''
   A number, a, is a power of b if it is divisible by b and a/b is a power of b.
   '''
   assert type(a) == int and type(b) == int and a > 0 and b > 0,\
       "is_power(a,b): both arguments must be positive integers"
   
   
   
   if a == b:
       result = True
   
   
   
   elif b == 1:
       result = False
   else:
       result = is_divisible(a,b) and is_power(a//b, b)
   assert type(result) == bool,\
       "is_power(a,b): the return result must be type of boolean"
   return result
def is_divisible(x, y):
   return x % y == 0
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))
print("is_power(121, 11) returns: ", is_power(121, 11))
                             
Comments