''' 20211004 Robin Dawes ''' def multiply_rec(x,y): '''multiply by repeated addition, using recursion x must be a positive integer ''' if x == 1: # base case return y else: # recursive part return y + multiply_rec(x-1, y) n1 = 23 n2 = 17 print("product of", n1, "and", n2, "is", multiply_rec(n1, n2)) def egyptian_multiply_rec(x,y): '''"Ancient Egyptian" mutiplication, revised to use recursion instead of a loop x must be a positive integer ''' if x == 1: # base case return y else: # recursive part if x % 2 == 1: return y + egyptian_multiply_rec(x // 2, y*2) else: return egyptian_multiply_rec(x // 2, y*2) print("product of", n1, "and", n2, "is", egyptian_multiply_rec(n1, n2))