You are on page 1of 1

def is_power(a, b):

# Checks whether a is a power of b.


print a, b
if a == b:
print 'a is a power of b'
return True
elif a % b == 0:
is_power(a/b, b)
else:
return False

It does. If I do
print is_power(4, 2),
it prints:

4 2
2 2
a is a power of b
None

You might also like