Python program to subtract two number using Function
- Home
- Calculations
- Python program to subtract two number using Function
- On
- By
- 0 Comment
- Categories: Calculations
Python program to subtract two number using Function
Python program to subtract two number using Function
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
- Variable declaration
- Read value from user
- function definition
- call the function
- display result on the screen
Code to subtract two integer number using Function
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
Code to subtract two float number using Function
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