Calculations

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

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
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

View Comments

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago