Write a Python Program to Add Two Numbers

Python is a high-level programming language that is widely used for various applications, including data science, machine learning, and web development.

One of the basic operations in programming is addition, which involves adding two numbers together.

In this tutorial, we will discuss how to add two numbers using Python.


To add two numbers in Python, we can use the “+” operator.

Here’s a simple Python program that takes two numbers as input from the user and then adds them together:

# Add two numbers in Python

num1 = input("Enter the first number: ")
num2 = input("Enter the second number: ")

# Add two numbers
sum = float(num1) + float(num2)

# Display the sum
print("The sum of {0} and {1} is {2}".format(num1, num2, sum))

In the above code, we first prompt the user to enter two numbers using the input() function.

Since the input() function returns a string, we convert the strings to float numbers using the float() function.

Next, we add the two numbers together using the “+” operator and store the result in a variable called sum.

Finally, we display the result using the print() function.

The format() method is used to substitute the values of the variables num1, num2, and sum in the output string.

Let’s run the above program and see what output we get:

Enter the first number: 5.6
Enter the second number: 3.4
The sum of 5.6 and 3.4 is 9.0

As you can see, the program correctly adds the two numbers and displays the result.


In conclusion, adding two numbers in Python is a simple task that can be achieved using the “+” operator.

By using the above Python program, you can add two numbers and display the result in just a few lines of code.