How to add two integer numbers in python

Two integer numbers can be added in python by taking the users input. In the following program number1 and number2 are storing the the two numbers from user by the input function. Two numbers are added and then print function is used to print the output.

First:

number1 = input('Enter the first number you want to add:')
number2 = input('Enter second number you want to add:')

sum = int(number1) + int(number2)

print('The sum of {0} and {1} is {2}'.format(number1, number2, sum))

Output

The following program like the above takes two numbers as input and prints the output after the addition.

Second:

number1 = int(input("Enter your first number to add:"))
number2 = int(input("Enter your second number to add:"))

sum = number1 + number2

print("The sum of the entered two integer numbers are:", sum)

Output

The following program simply add the two numbers and print the output.

Third:

number1 = 35
number2 = 40

print(number1 + number2)

Output :

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments