Python Program to Perform All Arithmetic Operations on Two Given Numbers
Python program to perform all arithmetic operations on two given numbers.
In this article, you will learn how to write a python program to perform all arithmetic operations on two given numbers.
Example
Enter any two positive integer numbers:
8
12
SUM 8 + 12 = 20
DIFFERENCE 8 - 12 = -4
PRODUCT 8 * 12 = 96
QUOTIENT 8 / 12 = 0.6666666666666666
MODULUS 8 % 12 = 8
You should have the knowledge of the following topics in python programming to understand this program.
- Python Arithmetic operators
- Python
input()
function - Python
print()
function
There we will perform these arithmetic operations like Sum, Difference, Multiplication, Division, and Modulus.
Source Code
# Python Program to Perform All Arithmetic Operations on Two Given Numbers
print("Enter any two positive integer numbers:")
p, q = int(input()), int(input())
sum, sub, mul, mod, div = 0, 0, 0, 0, 0
sum = p + q
sub = p - q
mul = p * q
div = p / q
mod = p % q
print("\n")
print("SUM ", p, " + ", q, " = ", sum)
print("DIFFERENCE ", p, " - ", q, " = ", sub)
print("PRODUCT ", p, " * ", q, " = ", mul)
print("QUOTIENT ", p, " / ", q, " = ", div)
print("MODULUS ", p, " % ", q, " = ", mod)
Output
Enter any two positive integer numbers:
8
12
SUM 8 + 12 = 20
DIFFERENCE 8 - 12 = -4
PRODUCT 8 * 12 = 96
QUOTIENT 8 / 12 = 0.6666666666666666
MODULUS 8 % 12 = 8
Explanation
In this given program, we have taken inputs 8
and 12
from the user then we applied arithmetic operations on these integer numbers.
Then this will be returned the 20
, -4
, 96
, 0.666
, and 8
output values of the above program.
Also, visit these links
C Program to Enter Marks of Five Subjects and Calculate Percentage and Grade
C++ Program to Calculate Percentage and Grade
Java Program to Calculate Grade of students
Python Program to Calculate Total Marks Percentage and Grade of a Student