The Python modulo operator can be used to create ciphers. You need to take the result, 17, and use mod to get its equivalent value in a twelve-hour context: On a twelve-hour clock, you can’t simply add 9 to 8 because you would get 17. The modulo operator is used when you want to compare a number with the modulus and get the equivalent number constrained to the range of the modulus.įor example, say you want to determine what time it would be nine hours after 8:00 a.m. A twelve-hour clock can be classified as “modulo 12,” sometimes shortened to “mod 12.”
When counting on a twelve-hour clock, you count up to the modulus 12 and then wrap back to 1. A twelve-hour clock has a fixed set of values, from 1 to 12.
All arithmetic operations performed on this number line will wrap around when they reach a certain number called the modulus.Ī classic example of modulo in modular arithmetic is the twelve-hour clock. Modular arithmetic deals with integer arithmetic on a circular number line that has a fixed set of numbers. The term modulo comes from a branch of mathematics called modular arithmetic. Free Bonus: Click here to get a Python Cheat Sheet and learn the basics of Python 3, like working with data types, dictionaries, lists, and Python functions.