In previous blog see saw what is python? and how it works with basic print statement to welcome you all.

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

Sample input :-

     2 3

Sample output :-

     5

Algorithm :-

  1. Start.
  2. Get the input of two numbers num1 and num2 in integer format.
  3. print the sum 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 adding the two numbers.
Output :-
  1. Program screenshot

  2. Output screenshot


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

Sample input :-

     2.04 3.01

Sample output :-

     5.05

Algorithm :-

  1. Start.
  2. Get the input of two numbers num1 and num2 in decimal format.
  3. print the sum 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 adding the two numbers.
Output :-
  1. Program screenshot



  2. Output screenshot


In next blog, we will see how to do difference of two numbers in python