To write a python program exponentiation (power of a number)
Here you will get an example to write a Python program exponentiation (power of a number).
Exponentiation is a mathematical operation that involves raising a base number to a certain power.
for example :
If we have 23, the base number is 2 and the exponent is 3. This means 2 raised to the power of 3 is calculated by multiplying 2 by itself 3 times:
23=2×2×2=8
So, 23 equals 8.
Example of Python program exponentiation (power of a number)
1 2 3 4 5 6 7 8 9 10 11 | def power(base, exponent): result = 1 for _ in range(exponent): result *= base return result # Test the power function base = 2 exponent = 5 result = power(base, exponent) print(base, "raised to the power of", exponent, "is:", result) |
Output
2 raised to the power of 5 is: 32
Check out our other Python programming examples