# 20210907 # R. Dawes # Egyptian Multiplication # Get the values num_1 = 125 num_2 = 3 # Initialize working variables product = 0 temp_1 = num_1 temp_2 = num_2 shrinking = [temp_1] doubling = [temp_2] # Execute the repeated halving of the first value and doubling of the second value while (temp_1 != 1): temp_1 = temp_1 // 2 temp_2 = temp_2*2 shrinking.append(temp_1) doubling.append(temp_2) # Add up the needed values how_many = len(shrinking) for i in range(how_many): if shrinking[i] % 2 == 1: product = product + doubling[i] # Show the result print("The product of",num_1,"and",num_2,"is",product)