In this program we will add two integers. If you have basic knowledge in any programming language, you can do this.

Please follow the simple steps as below.

Step 1: You can write the following code in any python editor such as IDLE.

x=12
y=13
sum=a+b
print('sum of 2 numbers  is',sum)

Step 2: Press enter key in & you will get the output
The output will be
          sum of 2 numbers is 25

Code Explanation


Notes 
: Line 1: a=12
                         Here a is a variable & 12 is stored in variable a
             Line 2: b=13
                         Here b is a variable & 13 is stored in variable b
             Line 3: sum=a+b
                         sum is a variable & the value of variable a & b is added & stored in sum variable.
             Line 4: print(‘sum of 2 numbers is’,sum)
                         The print() prints the output to screen .Here it prints sum variable.

python program to add two numbers with user input

using below code we will add two numbers and both numbers will entered by the user.

#Take input from keyboard for 1st number
no1 = int(input("Enter 1st No. : "))
#take input from keyboard for 2nd number
no2 = int(input("Enter 2nd No. : "))
#Add 2 numbers
sumofno =no1 + no2
#print the sum of nos in screen
print("The sum of 1st & 2nd no is :",sumofno)

I have written this program in IDLE. you can see the snapshot below.

Addition of 2 numbers with user Input

After executing the above program I got the below Output