Look more closely at the information you are given:
A number, a, is a power of b if it is divisible by b and a/b is a power of b.
It says "... and a/b is a power of b". It does not say "... and a is a power of b*b". There is a reason for that: you don't get the same results with the two different definitions.
Now look at your code for the recursive call:
return is_power(a,b*b)
We don't care if a is a power of b*b; we care if a/b is a power of b. So why are we calling is_power(a, b*b) # is a a power of b*b?
? Instead, we should call... well, I think you can figure it out :)
Why it's different: let's say the recursion happens twice. When we start out calling the function, let's say b = 2. On the first recursion, we pass 2 * 2 = 4. On the next recursion, the input was 4, so we pass 4 * 4 = 16. But we skipped the check for 2 * 2 * 2 = 8. 8 is a power of 2, but if we call is_power(8, 2)
, then is_power(8,8)
never happens, and then is_power(8, 16)
returns False.