Python Program to Add Two Numbers

Basic Python Program to Add Two Numbers

In this article, I will take you through a basic Python program to add two numbers. If you are a beginner in Python or any other programming language then generally this will be your second program after printing the “Hello, World”.

Also, Read – Machine Learning Full Course For free.

Python Program to Add Two Numbers:

To write a python program to add two variables is same as doing the addition of two integers mathematically. First, we need to declare two variables by assigning their values, and then we need to assign the sum of those two variables in a new variable.

Then we can simply print the output by printing the variable that is the sum of two variables. Let’s see how to do this with Python:

num1 = 5 num2 = 7 sum = num1 + num2 print(f"Addition of{num1, num2} is :{sum}")
Code language: PHP (php)

Addition of(5, 7) is :12

Now as we can see the output, it gives the sum of two numbers. Let’s see how we can add two numbers by taking user input. So now I will write a python program to add two numbers by taking a user input. Let’s see how we can do this:

num1 = input("Enter Number 1 :") num2 = input("Enter Number 2 :") sum = int(num1) + int(num2) print(sum)
Code language: PHP (php)

Enter Number 1 :10
Enter Number 2 :20

I hope you liked this article on how to write a Python program for the addition of two variables. Feel free to ask your valuable questions in the comments section below.

Follow Us:

Default image
Aman Kharwal

I am a programmer from India, and I am here to guide you with Data Science, Machine Learning, Python, and C++ for free. I hope you will learn a lot in your journey towards Coding, Machine Learning and Artificial Intelligence with me.

Leave a Reply