#!/usr/bin/python3 import math def bailey_borwein_plouffe_pi(n): result = 0 for k in range(n): result += (1/16)**k * ( 4/(8*k + 1) - 2/(8*k + 4) - 1/(8*k + 5) - 1/(8*k + 6)) return result if( __name__ == "__main__"): assert bailey_borwein_plouffe_pi(1000) == math.pi # Please note that the ``is`` operator checks wether the # two references are the same object, basically by comparing # their pointers. # # The ``==`` operator accesses the ``__eq__`` method of the # object that *compares* the other object to itself. # # Because ``a/b`` **cannot** return the same object as ``math.pi``, # the latter was created when the module ``math`` was initialized, # this will **always** evaluate to False.