# Multiplication_by_Iterative_Addition.py # # This program multiplies x by y by adding x y times iteratively. # # Anne Lavergne # March 2017 # Main part of the program ####### ### recursive funtion sum def multiply( x, y ): """ Iteratively implements the multiplication x * y using addition. Parameters: x, y - x is never mutated. Returned value: product i.e., x * y """ product = 0 for i in range(y): product += x return product # Main part of the program # Get user input operandList = input("Please, enter the two numbers you wish to multiply: ").split() # I am assuming that user input is valid # operand1 -> equationList[0] # operand2 -> equationList[1] # Future modification: validation user input operandList = [ int(operandList[i]) for i in range(len(operandList)) ] # x -> operandList[0] # y -> operandList[1] print("{} * {} = {} ".format(operandList[0], operandList[1], multiply(operandList[0], operandList[1]))) print("----")