This tutorial explains how to write a Simple Python Program to add two numbers using Arithmetic Operators.
Input:Â num 1 = 15, num 2 = 19 Output: 34
Addition program in Python Example 1
In the program below first, you need to declare two integer or float variables and then calculate the sum of both the variable using (+) arithmetic variable and store the value into 'sum' variable. And at last print the sum variable.
#python program to addÂ two numbers #Using Constant values #Declaring and Initializing two variables firstNumber = 10 secondNumber = 20 #Adding both numbers total = firstNumber + secondNumber #Printing the output print("Addition of",firstNumber,"and",secondNumber,"is =",total)
Addition of 10 and 20 is = 30
Addition program in Python: Taking Input from Users
In the program the user is asked to input two number then these inputs are scanned and stored in the variables 'firstNumber' and 'secondNumber'. Then variables 'firstNumber' and 'secondNumber' are added using (+) operator and the value is stored in variable 'total'. At last the variable 'total' is printed.
#python program to add two numbers #Using user input #Taking input from user firstNumber = float(input("Enter First Numbers : ")) secondNumber = float(input("Enter Second Number : ")) #Adding the numbers total = firstNumber + secondNumber #printing the output print("Addition of",firstNumber,"and",secondNumber,"is =",total)
Enter First Numbers : 0.8 Enter Second Number : 0.1 Addition of 0.8 and 0.1 is = 0.9
Note: SImilarly you can use subtract (-), multiply (*), divide(/) arithmetic operators instead of (+) arithmetic operator to subtract, multiply and divide two numbers in python respectively.