0

hi i have a big file filed with number. About 15 line of several number. Im trying to read it in roups of 4 lines and printing the result for every 4 lines. I have this code for now wich prints too many results id only want the final ones. But it also stops at the first four lines. is there a way to make it continue until the end? looking for this type of output:

Lignes 1-4 => 125
Lignes 5-8 => 2073
Lignes 9-12 => 559
Lignes 13-16 => 471

thank you in advance for any help.

for i in range(4):
line = ""
somme2 = 0
for i in range(4):
    line = fichNbr.readline().split()
    for n in line:
        somme2 += int(n)

print(somme2)
  • Could you edit your post and include an expected input and output? It may be easier to find an answer to your question! – Christopher Apple Apr 19 '17 at 03:10
  • 3
    Possible duplicate of [Python how to read N number of lines at a time](http://stackoverflow.com/questions/6335839/python-how-to-read-n-number-of-lines-at-a-time) – umutto Apr 19 '17 at 03:14

0 Answers0