top of page
Writer's pictureThe Tech Platform

How to raise a number to a power - Python



In Mathematical terms, an exponent refers to a number that is placed as a superscript of a number. It says how many times the base number is to be multiplied by itself. The Exponentiation is written as mⁿ and pronounced as "m raised to the power of n". Here "n" is the exponent and "m" is the base. It means m is to multiplies by m, n number of times. We cannot solve exponents like we normally do multiplication in Python.


Using exponent operator in Python

The exponent operator or the power operator works on two values. One is called the base and the other is the exponent. As explained earlier, the exponent tells the number of times the base is to be multiplied by itself.


Syntax:

m ** n

Code:

m = int(input("Enter the Base Number - "))
n = int(input("Enter the Exponent - "))

p = m ** n
print("The Answer is:" ,p)

Output:




Using pow() function for Python exponents:

Python has a built-in function that is useful for calculating power: pow(). It accepts two parameters which are a base and an exponent. It returns the modulus of the result. The result will always be a positive integer.


Syntax:

pow(m,n)

Code:

m = int(input("Enter the Base Number - "))
n = int(input("Enter the Exponent - "))

p = pow(m, n)
print("The Answer is:", p)

Output:




The Tech Platform


0 comments

Recent Posts

See All

Komentar


bottom of page