Codeforcoding

Subtract two numbers in Python programming

Subtract two numbers in Python programming

In this article, we will discuss the concept of the Subtract two numbers in Python programming

In this post, we are going to learn how to  write a program find the subtraction of two numbers in Python programming language

Subtract two numbers in Python programming
Subtract two numbers

Code to find the subtraction of  two numbers 

Subtract given two number

The program used to find the subtraction of given two numbers

Program 1

#Python program to subtract two numbers

num1=56.8; #variable declaration and initialization
num2=67.9;

#Subtract two numbers
sub=num2-num1;


#display the result of substraction

print("The subtract of {0} and {1} is {2}".format(num2,num1,sub) )

When the above code is executed , it produces the following result

The subtract of 67.9 and 56.8 is 11.1

Subtract given two numbers  with user input

This program allows the user to enter two numbers Then the program find the subtraction of the given two number

Program 2

#Python program to subtract two numbers

#stare the input numbers
num1=input("Enter the first number: ");
num2=input("Enter the second number: ");

#Subtract two numbers
sub=float(num2)-float(num1);


#display the substract

print("The subtract of {0} and {1} is {2}".format(num2,num1,sub) )

When the above code is executed , it produces the following result

Case 1

Enter the first number: 5.8
Enter the second number:9.8
The subtract of 9.8 and 5.8 is 4.0

case 2

Enter the first number: 7.8
Enter the second number: 5.3
The subtract of 5.3 and 7.8 is -2.5

 

Suggetsed for you

Operator in Python language

Data type in Python language

Introduction of Python language

 

Similar post

Sum of two number in Python

Sum of two number in Python using function

Sum of two number in Python using recursion

Calculate the sum of natural numbers in Python

Calculate the sum of natural numbers in Pyton using recursion

Calculate sum of odd and even number in Python language

Calculate sum of odd and even number of the list in Python language

C Program to find Subtraction of two numbers
C program to subtract two number using Function
Exit mobile version