def mySub(number1, number2): ''' Objective : To compute the sum of given two numbers. Input Variabes : number1 : integer - First number inputted by user. number2 : integer - Second number inputted by user. Return Value : Difference of given two numbers. ''' #Approach : Use of recursion and myIncrement function. if number2 != 0: number1 = pred.predecessor(number1) number1 = mySub(number1, pred.predecessor(number2)) return number1
def mySum(number1, number2): ''' Objective : To compute the sum of given two numbers. Input Variabes : number1 : integer - First number inputted by user. number2 : integer - Second number inputted by user. Return Value : Sum of given two numbers. ''' #Approach : Use of recursion and myIncrement function. if number2 == 0: return number1 else: return mySum(myIncrement(number1), pred.predecessor(number2))
def myMul(number1,number2): ''' Objective : To multiply two given numbers. Input Variabes : number1 : integer - First number inputted by user. number2 : integer - Second number inputted by user. Return Value : Product of given two numbers. ''' #Approach : Use of recursion, myIncrement and mySum function. if number1 == 0 or number2 ==0: return 0 elif number2==1: return number1 else: return mySum(number1,myMul(number1,pred.predecessor(number2)))