Jun 12, 2021
.
Admin
Hello Friends,
Now let's see example of how to addition between two number in python. We will show python add two number example. i would like to share with you how to addition two number in python. In this blog i will learn you how to add two variables in python.
Here i will give you add two numbers, the user is first asked to enter two numbers and the input is scanned using the input() function and stored in the variables number1 and number2. Then, the variables number1 and number2 are added using the arithmetic operator + and the result is stored in the variable sum.
So let's see the bellow example:
Example 1
add.py
# This program adds two numbers
number1 = 2.3
number2 = 5.8
# Add two numbers
total = number1 + number2
# Display the sum
print('The sum of {0} and {1} is {2}'.format(number1, number2, total))
Output :
The sum of 2.3 and 5.8 is 8.1
Example 2
add.py
# Store input numbers
number1 = input('Enter first number: ')
number2 = input('Enter second number: ')
# Add two numbers
total = float(number1) + float(number2)
# Display the sum
print('The sum of {0} and {1} is {2}'.format(number1, number2, total))
Output :
Enter first number: 2.5
Enter second number: 3
The sum of 2.5 and 3 is 5.5
Run python file:
python add.py
It will help you....
#Python