In this Python Program, we will learn how to calculate the Nth power of a number without using math.pow()
function or using math.pow()
function.
Here is the code of the program to calculate the Nth power of a number without using math.pow() function or using math.pow() function.
# Python Program to Find the Power of a Number Using For Loop
# To Take Input From the User
number = int(input("Enter any Positive Number: "))
exponent = int(input("Enter Exponent Value: "))
power = 1
for i in range(1, exponent + 1):
power = power * number
print("The Result of {0} Power {1} = {2}".format(number, exponent, power))
Enter any Positive Number: 5
Enter Exponent Value: 3
The Result of 5 Power 3 = 125
# Python Program to Find the Power of a Number Using While Loop
# To Take Input From the User
number = int(input("Enter any Positive Number : "))
exponent = int(input("Enter Exponent Value : "))
power = 1
i = 1
while(i <= exponent):
power = power * number
i = i + 1
print("The Result of {0} Power {1} = {2}".format(number, exponent, power))
Enter any Positive Number : 5
Enter Exponent Value : 3
The Result of 5 Power 3 = 125.0
# Python Program to Find the Power of a Number Using pow() Method
# Import Module
import math
# To Take Input From the User
number = int(input("Enter any Positive Number : "))
exponent = int(input("Enter Exponent Value : "))
power = math.pow(number, exponent)
print("The Result of {0} Power {1} = {2}".format(number, exponent, power))
Enter any Positive Number : 5
Enter Exponent Value : 3
The Result of 5 Power 3 = 125.0
Comments