# Python Program to Compute the Power of a Number – 2023

Hey guys, in this blog we will see a Python Program to Compute the Power of a Number.

## Example 1: Calculate the power of a number using a while loop

```# Python Program to Compute the Power of a Number

base = 5
exponent = 4

result = 1

while exponent != 0:
result *= base
exponent-=1

Output

`Answer = 625`
• Here we are using a while loop to calculate the power of a number.
• It just keeps on multiplying the base number exponential times.
• It is the most brute-force approach.

## Example 2: Calculate the power of a number using a for loop

```base = 5
exponent = 4

result = 1

for exponent in range(exponent, 0, -1):
result *= base

Output

`Answer = 625`
• Here we are using a for loop to calculate the power of a number.
• It is almost similar to the above approach.
• It just keeps on multiplying the base number exponential times.
• It is also a brute-force approach.
• Our for loop will go like 4,3,2,1.

## Example 3: Calculate the power of a number using the pow() function

```base = 5
exponent = -4

result = pow(base, exponent)

`Answer = 0.0016`