# 20210907 # R. Dawes # Egyptian Multiplication num_1 = 125 num_2 = 3 product = 0 temp_1 = num_1 temp_2 = num_2 #~ shrinking = [temp_1] #~ doubling = [temp_2] pairs = [(temp_1, temp_2)] while temp_1 != 1: temp_1 = temp_1 // 2 temp_2 = temp_2*2 #~ shrinking.append(temp_1) #~ doubling.append(temp_2) pairs.append((temp_1,temp_2)) #~ how_many = len(shrinking) #~ for i in range(how_many): #~ if shrinking[i] % 2 == 1: #~ product = product + doubling[i] for p in pairs: if p[0] % 2 == 1: product = product + p[1] print("The product of "+str(num_1)+" and "+str(num_2)+" is "+str(product))