Recursive multiplication

Report a typo

Imagine that suddenly all machines have gone insane and simple multiplication is not working for natural numbers anymore. Let's write a new function for this task recursively!

It's known that "a times b" is the same thing as "a plus itself b times". So we can rewrite the expression in the following way:

ab=a+a+a+a+...+aa*b = a + a+ a + a + ... + a

We need to reduce this problem to a smaller one with the recursive step, and then stop recursion with the base step.

Modify the template code below into a working function that takes two positive integers as its input and returns their product.

Sample Input 1:

1 1 

Sample Output 1:

1
Write a program in Python 3
def multiply(a, b):
# base case
if ...:
return a
# recursive case
return ...
___

Create a free account to access the full topic