Learn about Product of Two Numbers in Python using Recursion in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
Product of Two Numbers in Python using Recursion
# Python program to multiply two number using recursion
def product_num(num1,num2):
if(num1<num2):
return product_num(num2,num1)
elif(num2!=0):
return(num1+product_num(num1,num2-1))
else:
return 0
# inputs
num1 = int(input('Enter first number: '))
num2 = int(input('Enter second number: '))
product = product_num(num1, num2)
# print output
print("The Product of Number:", product)
Output:
Enter first number: 6 Enter second number: 4 The Product of Number: 24
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Code : Python Program to Multiply Two Numbers using Function