Hello, i would like to make program in python which reads the lines from an input file, which looks like this:
Bob
10
20
30
John
15
15
Kate
20
and the program sums the numbers for each person and writes into an output file which should look like this:
Bob
60
John
30
Kate
20
So far i can read the input file and write everything into the output file.
input = file("input.txt", "r")
output = file("output.txt", "w")
line = input.readline()
while line:
output.write(line)
line = input.readline()
input.close()
output.close()
I tried to sum the numbers but it says error because of the alphabetic. I wanted to sum the lines like line2 + line 3 + line4, line 6 + line 7, line 9 but i don't know how to sum lines.