Welcome to StackOverflow!
You have the right idea going, let's start by opening some files.
with open("text.txt", "r") as filestream:
with open("answers.txt", "w") as filestreamtwo:
Here, we have opened two filestreams "text.txt" and "answers.txt".
Since we used "with", these filestreams will automatically close after the code that is whitespaced beneath them finishes running.
Now, let's run through the file "text.txt" line by line.
for line in filestream:
This will run a for loop and end at the end of the file.
Next, we need to change the input text into something we can work with, such as an array!
currentline = line.split(",")
Now, "currentline" contains all the integers listed in the first line of "text.txt".
Let's sum up these integers.
total = str(int(currentline[0]) + int(currentline[1]) + int(currentline [2])) + "\n"
We had to wrap the int function around each element in the "currentline" array. Otherwise, instead of adding the integers, we would be concatenating strings!
Afterwards, we add the carriage return, "\n" in order to make "answers.txt" clearer to understand.
filestreamtwo.write(total)
Now, we are writing to the file "answers.txt"... That's it! You're done!
Here's the code again:
with open("test.txt", "r") as filestream:
with open("answers.txt", "w") as filestreamtwo:
for line in filestream:
currentline = line.split(",")
total = str(int(currentline[0]) + int(currentline[1]) + int(currentline [2])) + "\n"
filestreamtwo.write(total)