This is basic python program for all beginners in python programming language. It simply takes two integer numbers and performs arithmetic operations like addition, subtraction, multiplication, division, floor division, modulus and exponential(power) on them.
Arithmetic Operations โ Code Visualization
Task :
To perform arithmetic operations on two integers.
Approach :
- Read two input integers using
input()orraw_input(). - Addition operation using
+operator,num1 + num2adds 2 numbers. - Subtraction operation using
-operator,num1 - num2right hand operand from left hand operand. - Multiplication operation using
*operator,num1 * num2multiplies 2 numbers. - Division operation using
/operator,num1 / num2divides left hand operand by right hand operand. - Floor Division operation using
//operator,num1 // num2divides left hand operand by right hand operand, here it removes the values after decimal point. - Modulus
%operator when applied returns the remainder when left hand operand is divided by right hand operandnum1 % num2. - Exponential operation using
**operator,num1 ** num2returns value of num1 num2 - Print the result of each operation.
Program :
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
num1 = int(input('Enter First number: ')) num2 = int(input('Enter Second number ')) add = num1 + num2 dif = num1 - num2 mul = num1 * num2 div = num1 / num2 floor_div = num1 // num2 power = num1 ** num2 modulus = num1 % num2 print('Sum of ',num1 ,'and' ,num2 ,'is :',add) print('Difference of ',num1 ,'and' ,num2 ,'is :',dif) print('Product of' ,num1 ,'and' ,num2 ,'is :',mul) print('Division of ',num1 ,'and' ,num2 ,'is :',div) print('Floor Division of ',num1 ,'and' ,num2 ,'is :',floor_div) print('Exponent of ',num1 ,'and' ,num2 ,'is :',power) print('Modulus of ',num1 ,'and' ,num2 ,'is :',modulus) |
Output :

Course Suggestion
Want to be strong at OOP in Python? If yes, I would suggest you to take the course below.
Course:
Object Oriented Programming in Python
Pingback: Python program to find reverse of a number - Programming in Python