In previous blog see saw how to get the sum of two numbers

In today's blog we will see how to get the difference of two numbers.

Sample input :-

     8 3

Sample output :-

     5

Algorithm :-

  1. Start.
  2. Get the input of two numbers num1 and num2 in integer format.
  3. print the difference of two numbers.
  4. Stop.

Now lets see this in code with explanation.

Program :-

     num1 = int(input())

     num2 = int(input())

     print(num1 - num2)

Explanation :-

  1. num1 is a variable which stores the given number which we give in integer format because by default the input() reads the input as string so we use int() to convert that value to integer.
  2. Similarly, num2 is also a variable which stores the second number in integer format.
  3. print() is a function to print the output by subtracting the two numbers.
Output :-
  1. Program screenshot



  2. Output screenshot


Now lets see how to get the difference of two decimal numbers.

Sample input :-

     8.0 3.0

Sample output :-

     5.0

Algorithm :-

  1. Start.
  2. Get the input of two numbers num1 and num2 in decimal format.
  3. print the difference of two numbers.
  4. Stop.
Program :-
  
     num1 = float(input())
     
     num2 = float(input())

     print(num1 - num2)

Explanation :-
  1. num1 is a variable which stores the given number which we give in decimal format because by default the input() reads the input as string so we use float() to convert that value to decimal.
  2. Similarly, num2 is also a variable which stores the second number in decimal format.
  3. print() is a function to print the output by subtracting the two numbers.
Output :-
  1. Program screenshot


  2. Output screenshot


In next blog, we will see how do product of two numbers in python.