Python program to add two numbers with examples

Python program to add two numbers with examples

Python program to add two numbers with example

In this example, we will learn how to add two numbers in python

Example 1:-

#python program to add two numbers

a=10
b=15
c=a+b
print(c)

Output

25

Note:- In this example, we have given value 10 to variable a, and value 15 to variable b, and just ADD them and display output using the print function. 

Example 2:-

a=10
b=15
c=a+b
print(“a=”,a)
print(“b=”,b)
print(“addition of a and b= “,c)

Output

a=10
b=15
addition of a and b= 25

Note:- In this example, we are arranging the output of the program by showing the values of all variables.

Example 3:-

a=int(input(“enter first number: “))
b=int(input(“enter second number: “))
c=a+b
print(‘the sum of {0} and {1} is {2}’.format(a,b,c))

Output

enter first number: 10
enter second number: 15
the sum of 10 and 15 is 25

Note:- In this example, we asked the user to enter two numbers and then display the output in the formatted view.

If you like my post please share it with your friends by simply clicking the below social media button, and Don’t forget to comment so we will update ourselves.

Share in a Single Click

Leave a Reply

Your email address will not be published. Required fields are marked *