Python – Sum of Two Numbers

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.

  1. Start.
  2. Read first number.
  3. Read second number.
  4. Compute sum = first number + second number.
  5. Stop.

Python Program

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.

Output

Python program to find sum of two numbers

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.

Python Program

n1 = float(input('Enter first number : '))
n2 = float(input('Enter second number : '))

sum = n1 + n2
print('Sum =', sum)

Output

Python Program to Find Sum of Two Floating Point Numbers

Summary

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.