Python program to calculate the power using ‘pow()’ method

In this tutorial, we are going to learn a python program to calculate the power of a given number.

Problem Statement

For any two numbers that are inputs given by the user, one is the base value let’s say it as ‘x’ and the other is the exponent let’s say it as ‘y’, we have to print xy.

 For example:

Case1: If the user inputs the base of the number as 2 and exponent as 3

           then the output should be ‘8’.

Case2: If the user inputs the base of the number as 5 and exponent as 2.

            then the output should be ‘25’.

Our logic to calculate the power using ‘pow()’ method

  • Our program will take two inputs a base number and an exponent number from the user.
  • We will ‘pow’ function with arguments as the base number and exponent number.
  • Print the output

Algorithm to calculate the power using ‘pow()’ method

Step 1: Start

Step 2: take two inputs from the user one is the base number and the other is the exponent.

Step 3: print pow(base_number, exponent_number)

Step 4: Stop

Python Program to calculate the power using ‘pow()’ method

Output:

calculate power using pow method in python

Explanation:

                 For the input from the user, the base number is 6, and the exponent number is 3. The pow(6, 3) will return 63 i.e. 216.