Hello everyone, welcome to nkcoderz.com. In this article we will going to discuss about Python program to convert GCD of the given 2 numbers.
Code for python program to find the power ‘n’ of the given number ‘a’
def power(a, n): result = 1 for i in range(n): result *= a return result # test the function print(power(2, 3)) print(power(4, 2))
power(a, n) takes in two parameters,
n, and returns
a raised to the power of
n. It does this by using a for loop that iterates
n times, and in each iteration, it multiplies
The initial value of
result is set to 1 so that when the loop starts and the first time
a is multiplied, it is multiplied by 1.
If you liked this post, then please share this with your friends and make sure to bookmark this website for more awesome content.