Python Program to Subtract Two Numbers

Write a Python program to subtract two numbers. 

num1 = 128
num2 = 256

sub = num1 - num2
print('The Result of subtracting {0} from {1} = {2}'.format(num2,num1,sub))
The Result of subtracting 256 from 128 = -128

This Python program accepts two integer values and subtracts one number from the other.

num1 = int(input("Please Enter the First Number  = "))
num2 = int(input("Please Enter the second number = "))

sub = num1 - num2
print('The Result of subtracting {0} from {1} = {2}'.format(num2,num1,sub))
Python Program to Subtract Two Numbers

Few other outputs

Please Enter the First Number  = 11
Please Enter the second number = 43
The Result of subtracting 43 from 11 = -32

Please Enter the First Number  = 99
Please Enter the second number = 23
The Result of subtracting 23 from 99 = 76

Python program to subtract two numbers using functions.

def subtractTwoNum(a, b):
    return a - b

num1 = int(input("Please Enter the First Number  = "))
num2 = int(input("Please Enter the second number = "))

sub = subtractTwoNum(num1, num2)
print('The Result of subtracting {0} from {1} = {2}'.format(num2,num1,sub))
Please Enter the First Number  = 12
Please Enter the second number = 49
The Result of subtracting 49 from 12 = -37


Please Enter the First Number  = 70
Please Enter the second number = 37
The Result of subtracting 37 from 70 = 33

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.