Apr-23-2018, 08:39 PM
(Apr-23-2018, 08:31 PM)pyghorz Wrote: The solution to the problem is:def expo(a,n): if n == 0: return 1 elif n%2 == 0: return expo(a*a, n/2) elif n%2 == 1: return a*expo(a*a, (n-1)/2) a = int(input("Enter a: ")) n = int(input("Enter n: ")) print(expo(a,n))A test output is:Enter a: 4 Enter n: 4 256
def expo(a,n): if n == 0: return 1 elif n%2 == 0: return expo(a*a, n/2) elif n%2 == 1: return a*expo(a*a, (n-1)/2) a = int(input("Enter a: ")) n = int(input("Enter n: ")) print(expo(a,n))
I already have the solution. What I need to do is modify the function so that whenever it performs a multiplication, it prints out the multiplication process e.g. if it does 2*3, it prints out "2*3 = 6". I hope that is clear. Thanks.