I used those two codes and got different answers i would like to know why and other alternatives for this question
<p>The question is </p>

<pre><code>def sum_numbers_in_file(filename):
    """
    Return the sum of the numbers in the given file (which only contains
    integers separated by whitespace).
    &gt;&gt;&gt; sum_numbers_in_file("numbers.txt")
    19138
    """
</code></pre>

<p>this is my first code:</p>

<pre><code>rtotal = 0
myfile = open(filename,"r")
num = myfile.readline()
num_list = []

while num:
    number_line = ""
    number_line += (num[:-1])
    num_list.append(number_line.split(" "))
    num = myfile.readline()
for item in num_list:
    for item2 in item:
        if item2!='':
            rtotal+= int(item2)
return rtotal
</code></pre>

<p>this is my second code:</p>

<pre><code>f = open(filename)
m = f.readline()
n = sum([sum([int(x) for x in line.split()]) for line in f])
f.close()
return n
</code></pre>

<p>however the first one returns 19138 and the second one 18138</p>

<p>numbers.txt contains the following:</p>

<pre><code>1000 
15000 
2000 
1138
</code></pre>
