Program to Add Two Numbers in Python

Program to Add Two Numbers in Python

Here you will find the python program to add two numbers. We will discuss here Program to add two numbers in Python Programming. 

We will discuss here two examples. In the first example we will cover how to add two numbers using integer. In the second example we will cover how to add two numbers using float. 

To understand this concept you should have knowledge of Python Programming basic topics. So if you are new to Python Programming first you should learn the topics given below:

Introduction to Python

Basics of Python 

Python Operators

The program will first ask the user to enter two numbers, calculate their total and then print it.

input()

input () is a built-in function used to capture input from a user.

Example 1:

Program to Add Two Numbers in Python

In this program, we have asked the user to enter two numbers and this program indicates the sum number of two numbers entered by the user.

Integer()

Python code

a = int(input("enter first number:"))
b =
int(input("enter second number:"))
sum = a + b
print("Sum of two integer numbers is:",sum)
Output:
enter first number: 4 
enter second number: 12
Sum of two integer numbers is: 16

Example 2:

Program to add two numbers in Python using float().

Python code:

x = float(input('enter value of x:'))
y = float(input('enter value of y'))
z = x + y
print(z)
Output:
enter first number: 1.5
enter second number 2.5
4.0