Categories: category

Python program to find the sum of two numbers using recursion

Python program to find the sum of two numbers using recursion

In this tutorial, we will discuss a concept of the  Python program to find sum of two numbers using recursion

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

Find the sum of two numbers

Program

This program allows entering two digits to find the addition of two numbers using the recursive function in Python programming language

def sum(x,y):
     if(y==0):
        return x;
     else:
        return(1+sum(x,y-1));
x=int(input("Enter number first number: "))
y=int(input("Enter number second number: "))

print("Sum of two numbers are: ",sum(x,y))

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

Enter number first number: 35
Enter number second number: 40
Sum of two numbers are: 75)

Method

  1. Declare the two int type variables x,y x and y are used to receive input from the user.
  2. Receive input from the user for x, y to perform addition.
  3. When the function is called, two numbers will be passed as an argument. Subsequently,  the sum of the two numbers will be found.
  4. Display the result on the screen.

 

Similar post

Python code to the sum of two numbers

Python program to sum of two numbers using the function

Python program sum of numbers in a  list

 

Suggested for you

The operator in Python language

recursion in Python  language

if statements in Python  language

Function in Python language

 

Use of C program to find sum of two numbers using recursion
Calculate the sum of natural numbers in Python
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

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 days ago

C# inverted full pyramid star pattern

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

3 weeks ago

C# Full Pyramid star pattern program

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

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago