Table of Contents
In this tutorial, we will discuss the Python program to the addition of two numbers
In this post, we are going to learn how to find the sum of two numbers through different 4 ways in Python programming language
Program 1
#Python program add two integer
num1=34
num2=26
#Find sum of two numbers
sum=num1+num2
#Display the sum of two numbers
print("The sum of {0} and {1} is : {2}: ".format(num1,num2,sum)) When the above code is executed it produces the following output
The sum of 34 and 26 is : 60:
In this program
Program 2
#Python program add two integer
num1=int(input("Enter first number: "))
num2=int(input("Enter second number: "))
#Find sum of two numbers
sum=num1+num2
#Display the sum of two numbers
print("The sum of {0} and {1} is : {2} ".format(num1,num2,sum)) When the above code is executed it produces the following output
Enter first number: 123 Enter second number: 321 The sum of 123 and 321 is : 444
Approach
Program 3
#Python program add two integer
#Find sum of two numbers
def sumNunm(num1,num2):
sum=num1+num2
return sum
#Get input from user
num1=int(input("Enter first number: "))
num2=int(input("Enter second number: "))
result=sumNunm(num1,num2)
#Display the sum of two numbers
print("The sum of {0} and {1} is : {2} ".format(num1,num2,result))
When the above code is executed it produces the following output
Enter first number: 21 Enter second number: 39 The sum of 21 and 39 is : 60
Approach
Program 4
#Python program add two integer
#Find sum of two numbers
def sumNum(num1,num2):
if(num2==0):
return num1;
else:
return(1+sumNum(num1,num2-1));
#Get input from user
num1=int(input("Enter first number: "))
num2=int(input("Enter second number: "))
result=sumNum(num1,num2)
#Display the sum of two numbers
print("The sum of {0} and {1} is : {2}: ".format(num1,num2,result))
When the above code is executed it produces the following output
Enter first number: 124 Enter second number: 346 The sum of 124 and 346 is : 470:
Approach
Similar post
Java program to the addition of two numbers
C++ program to the addition of two numbers
C program to the addition of two numbers
Suggested for you
The operator in Python language
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.