How To Addition Two Number in Python ?
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....
- Get Last 2 Digits of Number in Python Tutorial Example
- How to Sum of First and Last Digit of Number in Python?
- How to Get First and Last Digit of Number in Python?
- Get the Last Digit of Number in Python Tutorial Example
- Get the First Digit of Number in Python Tutorial Example
- How to Remove All Decimals from Number in Python?
- How to Convert String to Float with 2 Decimal Places in Python?
- How to Format Number to 2 Decimal Places in Python?