# Lab_7_Exercise_1_Problem_1_a.py # a.k.a. Multiplication_by_Recursive_Addition.py # # This program multiplies x by y by adding x y times recursively. # # Anne Lavergne # March 2017 def multiply( x, y ): """ Recursively implements the multiplication x * y using addition. Parameters: x, y - x is never mutated. Returned value: product i.e., x * y """ if y == 0 : result = 0 # Base case 1 elif y == 1 : result = x # Base case 2 else : result = x + multiply( x, y - 1 ) # Recursive case return result # 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("----")