1. Write a function mu] t(n, m) that takes two integers n and m as inputs and re
ID: 662504 • Letter: 1
Question
1. Write a function mu] t(n, m) that takes two integers n and m as inputs and returns the product of those integers. To force you to use recursion, you may not use the multiplication operator (*). Rather, you should use recursion to add together n copies of m. For example, 4*5 = 5+ 5+ 5 + 5. Here are two examples of how mu] t should work: This function is similar to the [power function] [examples] from lecture. However, you will need a special case for when the first parameter is negative. To do so, add the following Note that this code uses the negation operator (-) to change the sign of a number. In particular: ? -n gives us the opposite of the value of n ? -mult(-n, m) gives us the opposite of the value returned by mult(-n, m).Explanation / Answer
def mult(n, m): t = 0 if n>0: for i in range(0,n): t += m return t elif n==0 or m==0: return 0 elif nRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.