 <p>That loop can't possibly end during your lifetime. <code>10 ** 100</code> is a really really enormous number. It's bigger than the number of particles in the universe, it's bigger than the number of the tiniest time periods that have passed since the creation of the universe. On an impossibly fast computer - <code>3 * 10 ** 46</code> millennia for the loop to complete. To calculate an infinite sum you'd wish to calculate until the sum has stopped changing significantly (e.g. the summands have fallen under certain very small threshold).</p> <p>Also, <code>xrange</code> and <code>range</code> in Python 2 are limited to the platform's long integers, which means that you can't have numbers higher than 2 ** 31 on a 32 bit machine and 2 ** 63 on a 64 bit one, (the latter is still too big to ever complete in your lifetime), this is why you get an <code>OverflowError</code> in Python 2. In Python 3 you'd get no error, but the summation will continue forever.</p> <p>And calculation factorial of such a large number is even slower, so you don't have a chance to ever exceed the maximum even on a 32 bit machine.</p> <p>Search for a function for calculating infinite sums, or do it yourself</p> <pre><code>&gt;&gt;&gt; from __future__ import division &gt;&gt;&gt; import itertools &gt;&gt;&gt; from math import factorial, cos, e &gt;&gt;&gt; for t in [0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1]: ... summables = ((4 ** (2 * n) * cos(2 * n * t)) / (e ** 16 * factorial(n)) ... for n in itertools.count()) ... print 0.5 * (1 + sum(itertools.takewhile(lambda x: abs(x) &gt; 1e-80, summables))) ... 1.0 0.973104754771 0.89599816753 0.77928588758 0.65382602277 0.569532373683 0.529115621076 0.512624956755 0.505673516974 0.502777962546 0.501396442319 </code></pre> <p>Also, I do not recognize the formula, but is this supposed to be <code>(e ** 16) * factorial(n)</code> or <code>e ** (16 * factorial(n))</code>? I just want to point out that you've written the former because of the other answer.</p>