Sum of Two Numbers in Python

(Last Updated On: 07/11/2022)

In this program, we will learn the sum of two numbers in python. Here we are performing two types of addition programs 1st is without user input and 2nd is with user input.

Python Program to Add(Sum) Two Numbers Without User Input

# Python Program to Add Two Numbers Without User Input

num1 = 15
num2 = 20

# Addition of two numbers
sum = num1 + num2

# Display the sum of two numbers
print('The sum of two number is {2}'.format(num1, num2, sum))

Output:

The sum of two number is 35

Python Program to Add(Sum) Two Numbers With User Input

# Python Program to Add Two Numbers With User Input

# Taking a number from user & Store as input numbers
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')

# sum of two numbers
sum = float(num1) + float(num2)

# Display the sum of two number
print('The sum of two number is {2}'.format(num1, num2, sum))

Output:

Enter first number: 14.5
Enter second number: 8.3
The sum of two number is 22.8

Leave a Reply

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