Check whether a number is a power of another number or not in Python

Here, we will figure out how to check if a number is an intensity of another number or not in Python programming language?

To take care of this issue basically, we will utilize the log() work from the math module. The math module gives us different scientific tasks and here we will utilize the log() work from this module.

In Python working of log() work, is equivalent to log work in science. Here, the client will give us two positive qualities an and b and we need to check whether a number is an intensity of another number or not in Python. The thought is easy to discover the log of a base b and takes its whole number piece and relegates it to a variable s.

After this simply check on the off chance that s to the intensity of b is equivalent to an, at that point an is the intensity of another number b. Prior to going to explain this, we will see the algorithm to take care of this issue and attempt to get it.

Algorithm to tackle this issue:

  1. At first, we will import the math module in the program.
  2. Takes the positive estimation of an and b from the client.
  3. Discover the log of a base b and allocate its whole number part to variable s.
  4. Additionally, discover the b to the power s and dole out it to another variable p.
  5. Check on the off chance that p is equivalent to an, at that point a will be an intensity of another number b and print an is the intensity of another number b.

Presently, we will compose the Python program by the usage of the above algorithm.

Program:

# 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))

Output:

RUN 1:
Enter two values: 1228 2
1228 is the power of another number 2.
	
RUN 2:
Enter two values: 15625 50
15625 is not the power of another number 50.

Leave a Comment

error: Alert: Content is protected!!