Table of Contents

Print the Difference of Two Numbers | Pictoblox

Example Description
Find the difference between two input numbers prompts the user to enter two numbers and then calculates and displays their difference."

Introduction:

In this Python program, we prompt the user to enter two numbers and then calculate the difference between them. The program then displays the calculated difference.

Code:

num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
diff = num1 - num2
print("The difference of",num1,"and",num2,"is",diff)

Logic:

1. Prompt the user to enter the first number.
2. Prompt the user to enter the second number.
3. Calculate the difference between the two numbers using the subtraction operator.
4. Print the message “The difference of [num1] and [num2] is [diff]”.

Output:

The difference of [num1] and [num2] is [diff]

>>Enter first number: 10

>>Enter second number: 11

>> The difference of 10 and 11 is -1