Subtract two numbers
Table of Contents
In this tutorial, we will discuss the Python program to subtraction of two numbers
In this post, we are going to learn how to find subtraction of two numbers via different 4 ways in Python language
Program 1
num1=432 #variable declaration
num2=234
sub=num1-num2 #calculation
print('Subtraction of {0} and {1} is: {2}'.format(num1,num2,sub))
#display the result When the above code is executed, it produces the following result
Subtraction of 432 and 234 is: 198
Approach
Program 2
#Subtraction of two numbers - using user input
num1=input("Enter first number ")
num2=input("Enter second number ")
#get input from the user
sub=num1-num2
#calculate subtraction
print('Subtraction of {0} and {1} is: {2}'.format(num1,num2,sub))
#display the result When the above code is executed, it produces the following result
Enter first number 2345 Enter second number 543 Subtraction of 2345 and 543 is: 1802
Approach
Program 3
#Python program to subtract two numbers using function
def subtract(a,b): #function definition
sub=a-b
return sub
num1=int(input("Please enter the first number "))#input number to num1 from user
num2=int(input("Please enter the second number "))#input number to num2 from user
result=subtract(num1,num2)#calling the function
print('Subtraction of the given numbers',result)#display the output When the above code is executed, it produces the following result
Please enter the first number 4321
Please enter the second number 1234
('Subtraction of the given numbers 3087)
Approach
Suggested post
Similar post
C program to subtraction of two numbers | 6 different Methods
C++ program to subtraction of two numbers | 6 different Methods
Java program to subtraction of two numbers | 5 different Methods
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.