Python program to find the power of any number x^y
ADVERTISEMENTS
Python program to find the power of any number x^y. There are you will learn how to find the power of any number x^y in Python language.
Formula:
r = b ^ y
where:
r = result
b = base value
y = exponent value
There are two ways to implement these formulae:
- By using the default method
- Second, by using the pow() function
1. By using the default method
# Python program to find the power of any number
print("Enter the base & exponent values::")
b, e, r, i = int(input()), int(input()), 1, 1
# b = base
# e = exponent
# r = result
# finding power of base value by equipping exponent value
while(i <= e):
r *= b
i += 1
# Output
print("Result:: ", b, "^", e, " = ", r)
Output:
Enter the base & exponent values::
5
7
Result:: 5 ^ 7 = 78125
2. By using the pow() function
# Python program to find the power of any number by using pow() function
print("Enter the base & exponent values::")
b, e, r, i = int(input()), int(input()), 1, 1
# b = base
# e = exponent
# r = result
# finding power of base value by equipping exponent value
r = pow(b, e)
# Output
print("Result:: ", b, "^", e, " = ", r)
Output:
Enter the base & exponent values::
5
7
Result:: 5 ^ 7 = 78125