Page

# 2.7 Programming Page 7

Completion requirements

### Operators - Data Manipulation Tools

The print statement can allow you to use Python as a calculator. The math operators are very similar to most calculators.

Operator | Name | Example | Meaning |
---|---|---|---|

+ | Addition | x + y | Add two operands or unary plus |

- | Subtraction | x - y | Subtract right operand from the left or unary minus |

* | Multiplication | x * y | Multiply two operands |

/ | Division | x / y | Divide left operand by the right (always results into float) |

% | Modulus | x % y | The remainder of the division of left operand by the right |

** | Exponentiation | x ** y | The left operand raised to the power of the right |

// | Floor Division | x // y | A division that results in the whole number adjusted to the left in the number line |

*Notes on division:

- The result of integer division is always rounded to the nearest integer value that is less than the real (not rounded) result.
- This is very important - Rounding always goes to the lesser integer.
- Do not try to:

- perform a
**division by zero** - perform an
**integer division by zero** - find a
**remainder of a division by zero**

#### Practice

Objectives

- becoming familiar with the concept of numbers, operators, and arithmetic operations in Python;
- experimenting with Python code

Scenario

In the compiler, write the provided expressions inside the print() functions.

a) print(2*4)

b) print(2**4)

c) print(2.*4)

d) print(2/4)

e) print(2//4)

f) print(-2/4)

g) print(-2//4)

h) print(2%4)

i) print(2%-4)