pow()
functionImport the math module as shown below in your Python environment.
Use the pre-defined math.pow(number,exponent)
function to find the power of the number.
import mathprint(math.pow(4,2))
Define the function, which takes two arguments:
Find the power of a number: multiply the number with itself the same number of times as the exponent’s value. We use the for…loop to achieve this task and store the result in the res variable.
Return the result stored in res, which is the required power of a number.
Finally, display the output.
def power(n,e):res=1for i in range(e):res *= nreturn resprint(power(4,2))
Define the function, which takes two arguments:
If the exponent/power is 0, then return 1.
If the exponent/power is 1 then return n, i.e., the number itself.
Otherwise, multiply the current number and call the power(n,e)
function recursively with
Finally, display the output, which is the desired power of the number.
def power(n, e):if e == 0:return 1elif e == 1:return nelse:return (n*power(n, e-1))n = 4p = 2print(power(n, p))