Given two numbers num1 and num2. The task is to write a Python program to find the addition of these two numbers.
Examples:
Input: num1 = 5, num2 = 3 Output: 8 Input: num1 = 13, num2 = 6 Output: 19
In the below program to add two numbers, the user is first asked to enter two numbers and the input is scanned using the input() function and stored in the variables number1 and number2. Then, the variables number1 and number2 are added using the arithmetic operator + and the result is stored in the variable sum.
Below is the Python program to add two numbers:
Example 1:
# Python3 program to add two numbers num1 = 15num2 = 12 # Adding two nos sum = num1 + num2 # printing values print("Sum of {0} and {1} is {2}" .format(num1, num2, sum)) |
Output:
Sum of 15 and 12 is 27
Example 2: Adding two number provided by user input
# Python3 program to add two numbers number1 = input("First number: ") number2 = input("\nSecond number: ") # Adding two numbers # User might also enter float numbers sum = float(number1) + float(number2) # Display the sum # will print value in float print("The sum of {0} and {1} is {2}" .format(number1, number2, sum)) |
Output:
First number: 13.5 Second number: 1.54 The sum of 13.5 and 1.54 is 15.04
Recommended Posts:
- Python Program for GCD of more than two (or array) numbers
- Python Program for Fibonacci numbers
- Python Program to Print Numbers in an Interval
- Python program to print all odd numbers in a range
- Python Program for Sum of squares of first n natural numbers
- Python program to count Even and Odd numbers in a List
- Python Program for cube sum of first n natural numbers
- Python program to print even numbers in a list
- Python program to print odd numbers in a List
- Python Program for Common Divisors of Two Numbers
- Python program to print all even numbers in a range
- Python program to print all negative numbers in a range
- Python program to print all positive numbers in a range
- Python program to print negative numbers in a list
- Python program to print positive numbers in a list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



