I have to write a script that does this:
Inputfile:
Name
10
-43
54
Name2
654
43
2
-5467
Name3
65
65
Outputfile:
Name 21
Name2 -4768
Name3 130
I came to the conclusion that I am supposed to split the input into arrays at the names and then print the first element and the sum of the rest, but I do not know how to do it and I haven’t really found anything about this on the web.
Some hints:
That should help you figure out what is a string and what not. It will also convert your input to a number for you.
Find out how to catch errors (
try,except).Find out how to read a file line by line. Try iterating over the file 😉
The rest is basic programming logic. Figuring it out yourself will give you most bang for the buck.