Python Example to subtract two integer without using minus operator
- Home
- Calculations
- Python Example to subtract two integer without using minus operator
- On
- By
- 0 Comment
- Categories: Calculations, multiply, subtraction
Python Example to subtract two integer without using minus operator
Python Example to subtract two integer without using minus operator
In this article, we will discuss the concept of the Python Example to subtract two integer without using minus operator
In this post, we are going to learn how to write a program to find the subtraction of two numbers with out using minus operator in Python programming language
Code to find the subtraction of two numbers
Subtract two integer using without minus
The program use to calculate subtraction of given two integer numbers using without minus operator in Python language
Program 1
num1=200#variable declaration num2=75 sub=num1+(~num2+1) #calculate subtraction without minus print('The subtraction of {0} and {1} is: {2}'.format(num1, num2, sub)) #display output
When the above code is executed, it produces the following result
The subtraction of 200 and 75 is: 125
Subtract two integer using without minus – takes user input
Program 2
The program allow the user to enter two numbers and then calculates subtraction of given two integer numbers using without minus operator in Python language
num1=int(input("Enter first number: ")) num2=int(input("Enter second number: ")) #ask input from the user #two input are stored in variable num1,num2 respectively sub=num1+(~num2+1) #calculate subtraction using without minus print('The subtraction of {0} and {1} is: {2}'.format(num1, num2, sub)) #display output on the screen
When the above code is executed, it produces the following result
case 1
Enter first number: 1000 Enter second number: 400 The subtraction of 1000 and 400 is: 600
Case 2
Enter first number: 400 Enter second number: 1000 The subtraction of 400 and 1000 is: -600
Suggested for you
if statements in Python language
Similar post
Subtract two numbers in Java language
Subtract two numbers using method in Java language
Subtract two numbers using recursion in Java language
Find sum of two numbers in Java
Find sum of two numbers in Java using recursion
Find sum of two numbers in Java without Arithmetic operator
Find sum of natural numbers in Java language
Find sum of natural numbers in Java language using recursion