python

Write a Program to Print the Sum of Two Numbers in Python

In this tutorial, we are going to see how to find the sum of two numbers in Python and display it using the print() function.

In the example below, we are going to use the addition operator (+).
 

 

Write a Program to Print the Sum of Two Numbers in Python
# ask the user to enter two numbers
nbr1 = input('Enter the first number: ')
nbr2 = input('Enter the second number: ')

# Add the two numbers
s = int(nbr1) + int(nbr2)

# print the sum of the integers
print('{0} + {1} = {2}'.format(nbr1, nbr2, s))

Output:

Enter the first number: 2 
Enter the second number: 2 
2 + 2 = 4
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *