THIS IS IN PYTHON 3.0
Let's call the first function power(a,b). Use the built-in power function a**b to write a second function called testing(c) that tests if the first function is working or not.
I already have the function power(a,b), which is as follows:
def power(a, b):
if (b == 0): return 1
elif (int(b % 2) == 0):
return (power(a, int(b / 2)) *
power(a, int(b / 2)))
else:
return (a * power(a, int(a / 2)) *
power(a, int(b / 2)))
*** I Kindly request you to Please provide a positive
rating******
Source code:
def power(a, b): # power function
if (b == 0):
return 1
elif (int(b % 2) == 0):
return (power(a, int(b / 2)) *
power(a, int(b / 2)))
else:
return (a * power(a, int(a / 2)) *
power(a, int(b / 2)))
def testing(c): # testing funtion of power
if(c== pow(a,b)):
return "power function is successfully tested ";
else:
return "power function does not work and not successfull!";
a = int(input("Enter an integer1 >>>"))
b = int(input("Enter an integer2 >>>"))
c= power(a,b)
print("result of power(a,b) =",c)
print("result of testing: \n ",testing(c));
Output:
Enter an integer1>>>4
Enter an integer2>>>2
power function is successfully tested
Get Answers For Free
Most questions answered within 1 hours.