Hello Coders, In this blog post, you will learn to add Two Numbers in Python. It is very easy to add Numbers in Python. We will add numbers with three different methods in Python. Let us learn these steps in detail:-
1. Simple Addition Program
In this type, Both numbers are given. We simply need to add these numbers. Forex:- Num1 = 3 , Num2 = 5 and the sum of num1 and num2 is num1 + num2 = 8. The Code and result of this problem are as follows:-
Simple.py
OUTPUT
Sum of both Number is = 8
2. Adding Number with User Input
In this type of Problem, We will take the value of both numbers from the user. The user will input the value of the number then the numbers will be scanned by the python after which the operation will be performed on them and the result will be stored and then displayed on the output screen. The Code and result of this problem are as follows:-
input.py
OUTPUT
Enter the value of 1st number : 41
Enter the value of 2nd number : 87
The Addition of both number is 128
3. Adding Number with Defining a Function
In this type, We will define a function sum which will add two numbers and whenever we will write sum and then numbers automatically the sum of these numbers will be displayed on the output screen. The Code and result of this problem are as follows:-
funcation.py
OUTPUT
The sum of these two numbers is 12
Hope this blog post was helpful to you and you have got the answer to your question. Thank you for visiting our blog. If you have any doubts about any coding questions then let us know in the comments section we will answer them as soon as possible. Till then check out our more blog posts.