Python Program to Find Sum of Two Numbers
To find sum of two numbers in Python, you can use Arithmetic Addition Operator
+ operator takes two operands and returns the sum of the two numbers.
Example 1: Sum of Two Integers
In this example, we shall take two integers and find their sum. Following are the steps we shall implement.
- Read first number.
- Read second number.
- Compute sum = first number + second number.
n1 = int(input('Enter first number : ')) n2 = int(input('Enter second number : ')) sum = n1 + n2 print('Sum =', sum)
input() function reads string from standard input. int() parses string to integer.
Example 2: Sum of Two Floating Point Numbers
You can use the same steps to find the sum of two floating point numbers. In this example, we shall read two floating point numbers and find their sum.
n1 = float(input('Enter first number : ')) n2 = float(input('Enter second number : ')) sum = n1 + n2 print('Sum =', sum)
In this tutorial of Python Examples, we learned how to find sum of two numbers in Python using Python Addition operator, with the help of example programs.
- Python String – Find the number of overlapping occurrences of a substring
- Python – Smallest of Three Numbers
- Python Program to Add Two Numbers
- Python – Sum of First N Natural Numbers
- Numpy sqrt() – Find Square Root of Numbers
- How to Swap Two Numbers in Python?
- Python – Check if Number is Armstrong
- How to Get Number of Elements in Pandas DataFrame?
- Python – Largest of Three Numbers
- Python Complex Number – Initialize, Access