def is_divisible(x,y):
if(x%y==0):
return True;
else:
return False;
def is_power(x,y):
if(x==1):
return True;
if(y==1):
return False;
if(is_divisible(x,y)==False):
return False;
return is_power(x//y,y);
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))
Comments
Leave a comment