In this tutorial we are going to learn a python program to find the sum of two numbers that are given by users.
Algorithm to find the sum of two numbers
BEGIN
READ num1 from the user
READ num2 from the user
SET sum = num1 + num2
DISPLAY sum
END
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
sum = num1 + num2
print("The sum of", num1, "and", num2, "is", sum)
Enter the first number: 10 Enter the second number: 20 The sum of 10 and 20 is 30
Explanation
To find the sum of two numbers, we follow these steps:
- We prompt the user to input the two numbers that need to be added.
- We read in the two numbers provided by the user and store them in variables.
- We add the two numbers together using the
+
operator and store the result in a variable called “sum”. - We output the value of “sum” to the user as the result of the calculation.
Online Compiler You can try onlinegdb
Python Coding Question : 100+ Python Interview Coding Question
2 thoughts on “Python Program to find the sum of two numbers”