To calculate the remainder of an Euclidean division in python, a solution is to use the modulo operator %, example:
>>> 10 % 20
since 10 = 2 * 5 + 0
>>> 10 % 31
since 10 = 3 * 3 + 1
Another solution is to use the python module "math" with the function math.fmod():
>>> import math>>> math.fmod(10.0,2.0)0.0>>> math.fmod(10.0,3.0)1.0>>> math.fmod(11.0,3.2)1.3999999999999995
since 11 = 3 * 3.2 + 1.3999999999999995
References
| Links | Site |
|---|---|
| Modulo (opération) | wikipedia |
| math — Mathematical functions | python doc |
| How to calculate a mod b in python? | stackoverflow |
| How does % work in Python? | stackoverflow |
