Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows:
7 x 4 = 4 + 4 + 4 + 4 + 4 + 4 + 4
(To keep the function simple, assume that x and y will always hold positive nonzero integers.)
#Create a multiply function with accepts
#two arguments:
# The function should return the value of x times y.
def multiply(x, y):
if y == 1:
return x
else:
#Recursive call, multiply
return x + multiply(x, y - 1)
# Test the function
x = int(input("Enter the first positive number: "))
y = int(input("Enter the second positive number: "))
result = multiply(x, y)
print("Product:", result)
Executed Output:
Enter the first positive number: 500
Enter the second positive number: 200
Product: 100000