Python has different types of operators for different operations. To create a calculator we require arithmetic operators.
Operator | Operator Name | Math sign & Example | . |
---|---|---|---|
+ | Addition | 15+7 = 22 |
.. |
- | Subtraction | 15-7 = 8 |
... |
* | Multiplication | 5*7 = 35 |
|
/ | Division | 5/3 = 1.666666667 |
|
** | Exponential | 5^3 = 125 |
|
% | Mudulas | 15%7 = 1 |
|
// | Floor Division | 15//7 = 2 |
Operator | Operator Name | Math sign |
---|---|---|
+= | Plus-Equals | counter+= 10 is counter= counter+10 |
1b | [✓] |
n = 15
m = 7
ans1 = n+m
print("Addition of",n,"and",m,"is", ans1)
ans2 = n-m
print("Subtraction of",n,"and",m,"is", ans2)
ans3 = n*m
print("Multiplication of",n,"and",m,"is", ans3)
ans4 = n/m
print("Division of",n,"and",m,"is", ans4)
ans5 = n%m
print("Modulus of",n,"and",m,"is", ans5)
ans6 = n//m
print("Floor Division of",n,"and",m,"is", ans6)
Here 'n' and 'm' are two variables in which the integer value is being stored. Variables 'ans1' , 'ans2' ,'ans3', 'ans4','ans5' and 'ans6' contains the outputs corresponding to addition, subtraction,multiplication, division, modulus and floor division respectively.