category

Find product of two numbers using recursion in Python

Find product of two numbers using recursion in Python

In this tutorial, we will discuss the concept of  Find product of two numbers in Python using recursion

In this article, we are going to learn  how to Find product of two numbers using recursion in the Python programming language

the Product of two numbers

Program

This program allows the entry of two digits from the user and to find the product of two numbers using the recursive function in Python programming language.

def product(num1,num2):
    if(num1<num2):
        return product(num2,num1)
    elif(num2!=0):
         return(num1+product(num1,num2-1))
    else:
         return 0

num1=int(input("Enter first number: "))
num2=int(input("Enter second number: "))

print("product is: ",product(num1,num2))

When the above code is executed, it produces the following results

Enter first number: 11
Enter second number: 22
product is: 242

Method

  • Declare three variables num1 and num2 as “int” type.
  • Receive two numbers from user and store variable as num1 and num2 respectively.
  • Product()  function is used to Calculate the product of of two numbers.
  • Call the function .
  • Display the result on the screen.

Similar post

Calculate the product of two numbers in C++ using recursion

Calculate the product of two numbers in Java using recursion

Calculate  the product of two numbers in C using recursion

 

Suggested for you

Function in Python language

Recursion in Python language

If statement in Python language

 

 

Find the product of two numbers in C using recursion
Find the product of two numbers using recursion in C++
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

Explanation of one dimensional array (Data structure)

Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…

2 days ago

Python program to calculate the sum of odd and even numbers in a list

Python program to calculate the sum of odd and even numbers in a list In…

5 days ago

Python code to Calculate sum of odd and even in a list

Python code to Calculate sum of odd and even in a list In this tutorial,…

1 week ago

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 weeks ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

1 month ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

2 months ago