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.