Python Snippets - 1(Arithmetic Operators)
Arithmetic operators are used with numeric values to perform mathematical operations. Python supports the following arithmetic operators
⑴ + Addition: To add two numbers i.e. a + b
⑵ - Subtraction: To find difference of two numbers i.e. a - b
⑶ * Multiplication: Product of two numbers e.g. 2 × 3 = 6
⑷ / Division: To find quotient in division i.e. returning the floating-point result of the computation
⑸ % Modulus: To remainder in division method
⑹ // Floor Division or Intger Division i.e. rounds the result down to the nearest whole number
⑺ ** Exponentiation e.g. find 12² = 144
The above said are also called binary arithmetic operator because it requires two operands.
Here is the python snippet (using Python 3) showing various arithmetic operations.
# eduvictors solutions # first program # Show binary arithmetic operations in python print("Python program to show binary arithmetic operations"); #addition of two numbers print("12 + 7 = ", 12 + 7); #subtraction print("12 - 7 = ", 12 - 7); #division print("12 ÷ 7 = ", 12 / 7); #multiplication print("12 × 7 = ", 12 * 7); #floor division print("12 // 7 = ", 12 // 7 ); #remainder print("12 % 7 = ", 12 % 7); #exponentiation print("12⁷ = ", 12 ** 7);
Program Output
No comments:
Post a Comment
We love to hear your thoughts about this post!
Note: only a member of this blog may post a comment.