Home >>Python Programs >Check if a number is a power of another number in Python
In this example, we will see a Python program through which we can check if a number is power of another or not.
In this program, we will use the log() function from the math module to solve the problem.
Algorithm:
# importing the module
import math
# input the numbers
a,b=map(int,input('Enter two values: ').split())
s=math.log(a,b)
p=round(s)
if (b**p)==a:
print('{} is the power of another number {}.'.format(a,b))
else:
print('{} is not the power of another number {}.'.format(a,b))