Modulus
Explore how the modulus operation calculates remainders through recursive subtraction. Understand the base and recursive cases, and see how to implement it in Python. This lesson helps you grasp the underlying concept of modulus using recursion, preparing you to solve related coding problems.
We'll cover the following...
What is the modulo operation?
The modulo operation (abbreviated as mod) returns the remainder when a number is divided by another number. The symbol for mod is %.
The number being divided is called the dividend. The number that divides the dividend is called the divisor.
The illustration below represents the concept of remainders using basic division example:
Mathematical Notation
The above illustration can be mapped on to the following equation:
Generically,
Implementation
Let’s take a look at the code:
Explanation:
Let’s discuss how we reached this solution. Examine the illustration below. If a number is divided by , it can give remainders: ...