Python Program to Add Two Numbers

Python Program to Add Two Numbers :

Today we will learn how to add two numbers in Python and display it. Here we will do it with the help of print()
function and “+” operator.



# Assigned 9 to variable number1
number1 = 9
# Assigned 5 to variable number2
number2 = 5

# Now add number1 and number2 and assigned the sum  to variable sum
sum = number1 + number2

# Now show the sum of two numbers

# Define the display format with numbers and output
print('The sum of {0} and {1} is {2}' .format(number1, number2, sum))


So, Final code:

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

Output :

Python Program to Add Two Numbers

Add Two Numbers in Python (Numbers input by Users)


# Numbers input by users

print("Welcome to https://bptutorials.com")
 
#  Here we store user input numbers in variable
#  numbers1 and number2

number1 = input('Enter number 1: ')
number2 = input('Enter number 2: ')


#  here we are adding two numbers
sum = float(number1) + float(number2)


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




Output :

program add two numbers in python and numbers input by users

Share This!

Leave a Reply

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