Python Program to Add Two Numbers

Python program to add two numbers; Through this tutorial, i am going to show you how to add two numbers in python.

In this tutorial, i will use arithmetic addition operator + to add two numbers in python . The addition operator accepts two operands and returns the result of addition.

Python Program to Add Two Numbers

  • 1: Simple Python Program to Add Two Numbers
  • 2: Python Program to Add Two Numbers with User Input
  • 3: Python Program to Add Two Numbers Using Functions

1: Simple Python Program to Add Two Numbers

a = 10
b = 20
 
sum = a + b
 
print("sum:", sum)

Output

sum: 30

2: Python Program to Add Two Numbers with User Input

See the following python program to add two numbers from user input; as shown below:

a = int(input("enter first number: "))
b = int(input("enter second number: "))
 
sum = a + b
 
print("sum:", sum)

Output

enter first number:10
enter second number:20
sum: 30

3: Python Program to Add Two Numbers Using Functions

See the python program to add two numbers using functions; as shown below:

# Program to illustrate
# the use of user-defined functions
def add_numbers(x,y):
   sum = x + y
   return sum
num1 = 15
num2 = 20
print("The sum is", add_numbers(num1, num2))

Output

sum: 35

Recommended Python Tutorials

Recommended:-Python Map() Method

Leave a Comment