;

Python Program To Add Two Numbers


Tutorialsrack 22/04/2020 Python

In this Python Program, we will learn how to perform the addition of two numbers and display the output using the print() function.

To perform an addition of two numbers, we've used the arithmetic addition operator + in the below program.

Here is the source code of the program to perform the addition of two numbers and display the output using the print() function.

Program 1 - To Add Two Numbers
# Python Program To Add Two Numbers

num1 = 5.5
num2 = 6.3

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

# Display the sum of Two Numbers
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
Output

The sum of 5.5 and 6.3 is 11.8

In this python program, we have taken the input from the user and perform an addition of two numbers and display the output. we use the input() function which is a built-in function in python programming language for taking input from the user. These functions take input as a string, so we need to convert it into a number by using the float() function.

Here is the source code of the program to take the input from the user and perform the addition of two numbers and display the output using the print() function.

Program 2 - To Add Two Number And Take the Input From the User
# Python Program To Add Two Numbers and Input Provided by Users

# Take the Input From the User
num1 = input('Enter the first number: ')
num2 = input('Enter the second number: ')

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

# Display the sum of Two Numbers
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
Output

Enter the first number: 52

Enter the second number: 52

The sum of 52 and 52 is 104.0

We can perform the other arithmetic operation by Changing this operator, we can subtract (-), multiply (*), divide (/), floor divide (//) or find the remainder (%) of two numbers.


Related Posts



Comments

Recent Posts
Tags