Project Euler #13 Python. Incorrect carry over
<p>This problem asks to sum up 100 numbers, each 50 digits long. <a href="http://code.jasonbhill.com/python/project-euler-problem-13/" rel="nofollow">http://code.jasonbhill.com/python/project-euler-problem-13/</a></p>

<p>We can replace <code>\n</code> with "\n+" in Notepad++ yielding</p>

<pre><code>a=37107287533902102798797998220837590246510135740250
+46376937677490009712648124896970078050417018260538
...
+20849603980134001723930671666823555245252804609722
+53503534226472524250874054075591789781264330331690
print(a)
</code></pre>

<p><code>&gt;&gt;37107287533902102798797998220837590246510135740250</code> (incorrect)</p>

<p>We can as well replace <code>\n</code> with <code>\na+=</code> yielding </p>

<pre><code>a=37107287533902102798797998220837590246510135740250
a+=46376937677490009712648124896970078050417018260538
...
a+=20849603980134001723930671666823555245252804609722
a+=53503534226472524250874054075591789781264330331690
print(a)
</code></pre>

<p><code>&gt;&gt;553...</code> (correct)</p>

<p>This seems to be a feature of BigInteger arithmetic. Under which conditions a sum of all numbers (Method 1) yields different result from an iterative increment (Method 2)?</p>

<p>Python source code lines are terminated by newline characters.  The subsequent lines in the first example are separate expression statements consisting of a single integer with a unary plus operator in front, but they don't do anything.  They evaluate the expression (resulting in the integer constant itself), and then ignore the result.  If you put all numbers on a single line, or use parentheses around the addition, the simple sum will work as well.</p>

python