- Get link
- X
- Other Apps
Add Two Numbers(integers) in Python
Hello Programmers!
Hope you are doing well. In this tutorial, I will tell you how to add two numbers(integers) using python. This is a very basic concept of Python.
The Whole code -
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
res = num1 + num2
print(res)
Step -1: Create a Python file
So first of all, you have to create a python file.
Step-2: Taking Input from user
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
In the above code, we are taking two inputs from the user. One for num1 & another for num2.
You may be wondering why we are adding int before the input function? The answer is, we are taking the input as an integer. If we don't add it then it will do this:
2 + 2 = 22
So when you are taking input as an integer then you have to add int before the input function. I hope that you have understood. But, still, if you have any confusion about this then write it in the comments.
Step-3: Adding two numbers
res = num1 + num2
In the above code, we are processing the two numbers. Actually, we are adding two numbers by the "+"(Add) operator. And we are storing the addition of num1 & num2 in a "res" variable.
Step-4: Printing the Addition
print(res)
In the above code, we are printing the res variable. We know that the addition of num1 & num2 is stored in the res variable so, when we say that print(res) then it will print the addition of num1 & num2 on the console.
Congratulations! Now you know how to add two numbers(integers) in python. Thank you for reading this tutorial. If You have any questions then write them in the comments below.
Join Facebook group -https://www.facebook.com/Python-Programming-106878491339183
python,add two numbers in python,adding two numbers in python,sum of two numbers in python,python tutorial,python tutorial for beginners,python in hindi,addition in python,python for beginners,integers in python,python programming,add two number in python,how to add two numbers in python,add two numbers in python using functions,sum of 2 numbers in python,create a function to add two numberes in python,python3,python program to add two numbers,add n natural numbers in python using functions
Comments
It’s actually a great and helpful piece of info. I’m happy that you just shared this helpful info with us. Please keep us informed like this. Thanks for sharing! Best python list methods service provider.
ReplyDelete