I'm doing my course exercise that states the following:
A number a is a power of b if:
- it is divisible by
b a/bis a power ofb.
Write a function called is_power that takes parameters a and b and returns True if a is a power of b.
However, I have to do it using recursion and somehow using the following function:
def is_divisible(x, y):
if x % y == 0:
return True
else:
return False
I don't know exactly where they relate to each other but yeah, that's what I'm supposed to do.
What I did so far (without using the above function) is:
def is_power(a, b):
while a % b == 0:
if a == b: return True
a = a / b
return False
print(10, 2)
Thoughts on why I have no output/how to relate the is_divisible function to is_power?
def is_powerif x % y == 0:andwhile a % b == 0:could probably replace one with the other using function call