Python program to calculate exponential power of a number

Write a program to find the exponential power of a number. In this Python  Programming example, we are going to write a program to find the exponential power of any number.

What is Exponential Power?

Multiplying a number with itself for multiple times is exponents  likewise  5² = 25, 5³=125, 12³=1728

calculate it as 5×5=25, 5x5x5=125,12x12x12=1728

here 5,12 are the base and the 2 and 3 is the power of that bases

Algorithm of Exponential Power

  • Taking the input of base and power and convert them into integer type
  • Using loop to operate the logic
  • Printing the result with a message

Python Program to find the exponential power of a number

a= int(input("enter a number"))
b= int(input("enter a power"))
if b==0:
    print(1)
else:
    for i in range(1,b+1):
        result=a**i
    print(result)

Explanation of the Code

On-Line no:1 and On-Line no:2  we took the input of base and power and convert them into integer type

On-Line no:3 checking the power if it is zero or  not

On-Line no:4  if zero print one as if zero is the power of any base then the answer is 1

On-Line no:5  else block starts from here

On-Line no:6  using for loop which starts from 1 and runs up to the power entered

On-Line no:7 dumping the output of operation into variable

On-Line no:8  printing the result we got

 

Output

In this blog, we learned how to create a program to calculate the power of a number