Python Program to find difference of two integer numbers

Program

a = int(input('Enter number for a: '))
b = int(input('Enter number for b: '))
difference = a - b
print('Difference = ', format(difference))

This program inputs two numbers, calculates their difference, and prints the result. This simple program demonstrates basic input, output, and arithmetic operations in Python.

a = int(input('Enter number for a: '))
b = int(input('Enter number for b: '))
  • input() function takes user input as a string.
  • int() function converts the input to an integer.
  • The user enters two numbers (a and b).
difference = a - b
  • Subtraction (-) is performed, and the result is stored in difference.
print('Difference = ', format(difference))
  • Prints the difference using the format(difference) function.

Key Takeaways:

  1. User inputs two numbers.
  2. Conversion to integers using int().
  3. Subtraction operation (-) is performed.
  4. Result is displayed using format().

Output

Enter number for a: 56
Enter number for b: 12
Difference =  44