Python Program - 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.

https://youtu.be/V82fzt0Q2FM?si=b7XMgZV1ZUayQXwM

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. Take two numbers in n1, n2.
  3. Compute sum of the two numbers.
  4. Stop.

Python Program

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

Output

Sum = 28

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 = 1.23
n2 = 0.54
sum = n1 + n2
print('Sum =', sum)

Output

Sum = 1.77

Summary

In this tutorial, we learned how to find sum of two numbers in Python using Addition operator, with the help of example programs.