Python Addition Two Number Example Tutorial

Published On: 16/06/2022 | Category: Python

Hi Guys,

In this quick example, let's see python addition two number example tutorial. you can see how to add two variables in python. I would like to show you python program to find sum of n numbers. let’s discuss about python addition two number example tutorial for beginners. So, let's follow few step to create example of python addition program.

So let's see the bellow example:

Example : 1 main.py
# This program adds two numbers
number1 = 4.5
number2 = 5.4

# 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 4.5 and 5.4 is 9.9
Example : 2

In this second example 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.

main.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: 25
Enter second number: 50
The sum of 25 and 50 is 75.0
Run python file:
python3 main.py
Output

I Hope It will help you....