Python Program to Add two numbers

In this python tutorial, we will learn to add two numbers in python. We add two numbers by using 2 methods, first, add two numbers by using a simple variable then in the second program we take input from the user and then we add the two numbers.

Add Two Numbers using the python program

Steps to approach this program:

  1. First, assign integer values in a and b.
  2. Then print the sum of the number.

Program:

1
2
3
4
5
a = 10  #a is 10 
b = 20  #b is 20

#print the sum of a and b
print("Sum of two number is: ",a+b) 

Output:

The Sum of two numbers is: 30

Add Two Numbers by Taking Input From the User

Steps to approach this program:

  1. First, take the input of integer number by using python input() inbuilt function and int() function
  2. Then print the sum of a and b

Program

1
2
3
4
5
a = 10  #a is 10 
b = 20  #b is 20

#print the sum of a and b
print("Sum of two number is: ",a+b) 

Output

Enter first number: 10 Enter second number: 20 Sum of two numbers is: 30
Next Post Previous Post
No Comment
Add Comment
comment url