Arithmetic Operator

Arithmetic Operators:

Arithmetic Operaor is Used to perform common mathematical operations like addition, subtraction, etc.

OperatorDescriptionExample
+ additionAdd two operandsa+b
- SubtractionSubtracts right hand operand from left hand operand.a-b
* MultiplicationsMultiplies values on either side of the operatora*b
/ DivisionDivide left operand by the right one (always results into float)a/b
% ModulusDivides left hand operand by right hand operand and returns remaindera % b
// Floor DivisionFloor division - division that results into whole number adjusted to the left in the number linea//b
** Exponentleft operand raised to the power of righta**b

Arithmetic Operator - Program Link

a=int(input())
b=int(input())
print("addition ",a+b)
print("Subtraction ",a-b)
print("Multiplication ",a*b)
print("Division ",a/b)
print("Floor Division",a//b)
print("Modulo ",a%b)
print("Exponentiation ",a**b)
print("Floor division negative number",-3//2)

Output

addition 5
Subtraction 1
Multiplication 6
Division 1.5
Floor Division 1
Modulo 1
Exponentiation 9
Floor division negative number -2

References

  • Allen B. Downey, “Think Python: How to Think Like a Computer Scientist‘‘, 2nd edition, Updated for Python 3, Shroff/O‘Reilly Publishers, 2016 (http://greenteapress.com/wp/thinkpython/)
  • Guido van Rossum and Fred L. Drake Jr, ―An Introduction to Python – Revised and updated for Python 3.2, Network Theory Ltd., 2011.
  • John V Guttag, ―Introduction to Computation and Programming Using Python‘‘, Revised and expanded Edition, MIT Press , 2013
  • Robert Sedgewick, Kevin Wayne, Robert Dondero, ―Introduction to Programming in Python: An Inter-disciplinary Approach, Pearson India Education Services Pvt. Ltd., 2016.
  • Timothy A. Budd, ―Exploring Python‖, Mc-Graw Hill Education (India) Private Ltd.,, 2015. 4. Kenneth A. Lambert, ―Fundamentals of Python: First Programs‖, CENGAGE Learning, 2012.
  • Charles Dierbach, ―Introduction to Computer Science using Python: A Computational Problem-Solving Focus, Wiley India Edition, 2013.
  • Paul Gries, Jennifer Campbell and Jason Montojo, ―Practical Programming: An Introduction to Computer Science using Python 3‖, Second edition, Pragmatic Programmers, LLC, 2013.