Source: https://www.irif.fr/~sangnier/enseignement/IP1-Python/IP1-Python-cours-td-5-7.pdf