In this **python tutorial**, you will learn **how to Calculate the Power of a Number** using the while loop and the pow() function along with the different operators of the python programming language.

## How to Calculate the Power of a Number?

Letâ€™s take a look at the first source code , here the values are given as input by the user in the code, the operators and while loop along with the assignment operators carry out the function.

RUN CODE SNIPPETbase = int(input("Enter the base number: ")) exponent = int(input("\nEnter the exponent number: ")) result = 1 while exponent != 0: result *= base exponent-=1 print("\nThe Power of the number: " + str(result))

**INPUT:**

3 4

**OUTPUT:**

Enter the base number: Enter the exponent number: The Power of the number: 81

- Here we give the user the option to enter the values and the input values are scanned using the
`input`

function and are stored in the variable`base`

and`exponent`

with the statements/strings`("Enter the base number: ")`

and`("\nEnter the exponent number: ")`

Â , we use the`int`

Â function and declare theÂ input value as an integer value. - We assign the variable
`result`

with the integer`1`

. - Next, we declare a
`while`

Â loop with the condition`exponent != 0`

followed by a`:`

, after which we declare the condition`result *= base`

and`exponent-=1`

. - In this code we use the while loop, where we multiply the
`result`

with the`base`

until the`exponent`

condition is satisfied that is it becomes`0`

. - In theÂ
**STDIN**Â section of the code editor the input values are entered. - The final output values are displayed with the statement
`("\nThe Power of the number: " + str(result))`

using the`print`

function, where the`+ str(result))`

returns and displays the string version of the`result`

value.

Letâ€™s take a look at the second source code , here the values are given as input by the user in the code, the pow() function along with the print statement carry out the function.

RUN CODE SNIPPETbase = int(input("Enter the base number: ")) exponent = int(input("\nEnter the exponent number: ")) result = pow(base, exponent) print("\nThe Power of the number: " + str(result))

**INPUT:**

4 3

**OUTPUT:**

Enter the base number: Enter the exponent number: The Power of the number: 64

- Here we give the user the option to enter the values and the input values are scanned using the
`input`

function and are stored in the variable`base`

and`exponent`

with the statements/strings`("Enter the base number: ")`

and`("\nEnter the exponent number: ")`

Â , we use the`int`

Â function and declare theÂ input value as an integer value. - In theÂ
**STDIN**Â section of the code editor the input values are entered. - We declare the
`result`

variable to the function`pow(base, exponent)`

. - The final output values are displayed with the statement
`("\nThe Power of the number: " + str(result))`

using the`print`

function, where the`+ str(result))`

returns and displays the string version of the`result`

value.

**NOTE:**

- TheÂ
**While true**Â loop in python runs without any conditions until the break statement executes inside the loop. - TheÂ
**colon :**Â at the end of the if and else statement tells Python that the next line of code should only be run if the condition is true. - TheÂ
**str() function**Â in python returns the string version of the object. - TheÂ
**!= operator**Â is defined asÂ**not equal to operator**. It returns True if operands on either side are not equal to each other, and returns False if they are equal. - The
***= multiplication assignment operator**multiplies a variable by the value of the right operand and assigns the result to the variable. - The
**-= subtraction assignment operator**subtracts right operand from the left operand and assigns the result to left operand. - The
**pow()**function of the python programming language returns the value of x to the power of y (x^{y}). - The statement for the input function are enclosed inÂ
**single quotes**Â andÂ**parenthesis**. - TheÂ
**\n**Â in the code indicates a new line or the end of a statement line or a string. - The
**Â print**Â statement/string to be displayed in enclosed in double quotes. - TheÂ
**input()**Â function allows a user to insert a value into a program, it returns a integer value. - The statement for the input function are enclosed inÂ
**single quotes**Â andÂ**parenthesis.**