def isPower (num, base):
if base in {0, 1}:
return num == base
power = int (math.log (num, base) + 0.5)
return base ** power == num
print isPower (8,2) # false
print isPower (64,4) # true
Share
def isPower (num, base):
if base in {0, 1}:
return num == base
power = int (math.log (num, base) + 0.5)
return base ** power == num
print isPower (8,2) # false
print isPower (64,4) # true
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
0 Replies