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

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

6 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

6 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

6 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

9 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

1 year ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

1 year ago