Subtract Two Numbers in Python

(Last Updated On: 09/11/2022)

In this program, we accept input from the user and subtract two numbers in python.

Python Program to Subtract Two Numbers Using Integer

# Subtract Two Numbers in Python

# we are taking a number from user as input
# entered value will be converted to int from string
num1 = int(input("Enter the First Number: "))
num2 = int(input("Enter the Second Number: "))

output = num1 - num2

#display the subtraction
print("Subtract Two Number using integer",output)

Output:

Enter the First Number: 92
Enter the Second Number: 63
Subtract Two Number using integer 29

Python Program to Subtract Two Numbers Using Float

# Subtract Two Numbers in Python

# we are taking a number from user as input
# entered value will be converted to float from string
num1 = input("Enter the First Number: ")
num2 = input("Enter the Second Number: ")

output = float(num1) - float(num2)

#display the subtraction
print("Subtract Two Number using float variable",output)

Output:

Enter the First Number: 5.6
Enter the Second Number: 1.1
Subtract Two Number using float variable 4.5

Leave a Reply

Your email address will not be published. Required fields are marked *