# Python Program to Check IF a Number is Power of Another Number

Python program to check if an integer a number is the power of another integer number; In this tutorial, you will learn how to check if a number is a power of another number python.

## Python Program to Check IF a Number is Power of Another Number

• Algorithm to Check IF a Number is Power of Another Number
• Program to check if a number is power of another number in python
• Python program to check if a number is power of another number using While loop

### Algorithm to Check IF a Number is Power of Another Number

• Import the math module in the python program.
• Allow user to input values.
• Find the log of a base b and assign its integer part to variable x.
• Also, find the b to the power x and assign it to another variable y.
• Check if y is equal to a then a is a power of another number b and print a is the power of another number b.

### Program to check if a number is power of another number in python

In this program, we will use the log() function from the python math module. After that, allow user to input values. And we have to check whether a number is a power of another number or not in Python by using max.log() function.

```# Python program to check if a number is power of another number

# import math module
import math

# input the numbers
a,b=map(int,input('Enter two values: ').split())

x=math.log(a,b)

y=round(x)

if (b**y)==a:
print('{} is the power of another number {}.'.format(a,b))
else:
print('{} is not the power of another number {}.'.format(a,b))

```

Output

```Enter two values:  1000 10
1000 is the power of another number 10.```

### Python program to check if a number is power of another number using While loop

In this program, we will use the python while loop with function. After that, allow user to input values. And we have to check whether a number is a power of another number or not in Python by using a function and while loop.

```# Python program to check if a number is power of another number

# Returns true if y is a power of x
def isPower (x, y):

# test conditions
if (x == 1):
return (y == 1)

# Repeatedly compute
pow = 1
while (pow < y):
pow = pow * x

# return
return (pow == y)

a,b=map(int,input('Enter two values: ').split())

# call function and print result

if(isPower(a, b)):
print('{} is the power of another number {}.'.format(a,b))
else:
print('{} is not the power of another number {}.'.format(a,b))
```

Output

```Enter two values:  10 1
10 is the power of another number 1.```

## Recommended Python Programs 