read from source file and write to target file line by line until the end of the source file. add the numbers in the source file and write to target file the sum.
def add_nums(source_file, target_file): fh = open(source_file, 'r') total = 0 for line in fh: total += int(line) fh.close() fh = open(target_file, 'w') fh.write(str(total)) fh.close() add_nums('numbers.txt', 'sum.txt')