Do you know Subtraction of Two numbers in python programming is so easy ? There is only 2 steps to perform the Subtraction. In the below program to Subtraction two numbers in python, the user is first asked to enter two numbers. The input is scanned using the input() function and stored in the variables num1 and num2. The variables num1 and num2 are Subtracted using the arithmetic operator – . Then result is stored in the variable sub. Then the user prints the output using the print() function.
Well, you can take more than 2 inputs and store in different variables and able to perform the Subtraction of numbers in python. And then print the output using print function. Similarly, you can able to perform the addition , multiplication as well as the division operation. Using the respected symbols used for the particular operation you can able to perform the operation. In below you can able to find the link for addition of Two numbers in Python (Using 2 steps), Multiplication of Two numbers in Python (Using 2 steps) and how to Learn Python Programing from basics.
Here are the steps written below to perform the addition operation :-
Step 1 – Take two numbers from the user as input by using the input() function and store the numbers in the variables namely num1 and num2.
num1=int(input("enter 1st integer no.")) num2=int(input("enter 2nd integer no."))
Step 2 – Then just subtract the variable num1 and num2 using arithmetic operator ‘-‘ and the store the result in a new variable sub.
sub = num1 - num2 print("the Subtraction of",num1 ,"and",num2 ,"are", sub)
The code for printing the subtraction is written below
How to subtract two numbers in python
# Subtraction of two numbers #take two user input number and subtract them num1=int(input("enter 1st integer no.")) num2=int(input("enter 2nd integer no.")) sub = num1 - num2 print("the Subtraction of",num1 ,"and",num2 ,"are", sub)
Here as you can see that after execution of the program the output will going to be like this:
- Learn Python Programing from basics – Click here
- Learn with us on YouTube – Click here
- Multiplication Two numbers in Python (Using 2 steps)– Click here