Michelle Chan - 1 month ago 5x

Python Question

I am doing exercise on Singpath and I am stuck at this question. This question is under recursion exercises but I have no idea what the question means.

A number,, is a power of`a`

if it is`b`

divisible byand`b`

is a power of`a/b`

.`b`

Write a function called`is_power`

that takes parametersand`a`

and`b`

returnsif`True`

is a power of`a`

.`b`

Just thought of the answer and I've posted it below.

Answer

Here is my answer...

```
def is_power(a,b):
if(a%b != 0):
return False
elif(a/b == 1):
return True
else:
return is_power(a/b,b)
```

Source (Stackoverflow)

Comments