# Modulo: the rest is important¶

## Objectives¶

 The modulus operator is used twice in Python. Once for the formatted output of texts and secondly for the calculation of the remainder, after a integer division. What this operator can be used, is shown here.

## Instructions¶

1. What is the result if the calculation of the number 3 is performed?
2. Search for some aother examples you can find on the internet.

## Calculating with the modulo operator %¶

This example is using a for loop:

for i in range(1,11):
print('{} divided by {} is {} and the reminder is {}'.format(i, 2, i/2, i % 2))


The result:

1 divided by 2 is 0 and the reminder is 1
2 divided by 2 is 1 and the reminder is 0
3 divided by 2 is 1 and the reminder is 1
4 divided by 2 is 2 and the reminder is 0
5 divided by 2 is 2 and the reminder is 1
6 divided by 2 is 3 and the reminder is 0
7 divided by 2 is 3 and the reminder is 1
8 divided by 2 is 4 and the reminder is 0
9 divided by 2 is 4 and the reminder is 1
10 divided by 2 is 5 and the reminder is 0


Question: What can you achieve?

Answer: It is clear which number is even (rest = 0) and that number
is odd (residual = 1).

Question: Where do I need this?

Answer: For example, the different coloring of the table rows.
No matter how long the table is, the color is always exchanged in the exchange, and thus the table more readable.
In Blender we use the modulo operator to assign materials in exchange, each plot.

Other examples can be found under http://en.wikipedia.org/wiki/Euclidean_division