In this tutorial, we will discuss the Python program to subtract two number using Function
In this topic, we are going to learn how to subtract two numbers (integer, floating point) using the function in Python language
already we are learned the same concept using the operator
if you want to remember click here, Python program to subtract two numbers
Approach
The program allows to enter two integer values then, it calculates subtraction of the given numbers
Program 1
#python program to subtract two numbers using function def subtraction(x,y): #function definifion for subtraction sub=x-y return sub num1=int(input("please enter first number: "))#input from user to num1 num2=int(input("please enter second number: "))#input from user to num2 print("Subtraction is: ",subtraction(num1,num2))#call the function
When the above code is executed, it produces the following result
case 1
please enter first number: 100 please enter second number: 46 Subtraction is: 54
case 2
please enter first number: 54 please enter second number: 110 Subtraction is: -56
The program allows to enter two float values then, it calculates subtraction of the given numbers
Program 2
#python program to subtract two float numbers using function def subtraction(x,y): #function for subtraction sub=x-y return sub num1=float(input("please enter first number: "))#input from user to num1 num2=float(input("please enter second number: "))#input from user to num2 print("Sum is: ",subtraction(num1,num2))#call thefunction
When the above code is executed, it produces the following result
case 1
please enter first number: 56.7 please enter second number: 45.6 Subtraction is: 11.1
Suggetsed post
Function in Python programming language
Similar post
Subtract two numbers in Java language
Subtract two numbers in C language
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…