Cody Bable

Generation

generate functionSun, 23 Apr 2023

read from source file and write to target file line by line until the end of the source file. use a function to add the numbers in the source file and write to target file the sum.

def read_file(source_file, target_file): sum = 0 target = open(target_file, 'w') with open(source_file) as f: for line in f: sum += int(line) target.write(line) target.write(sum)

Questions about programming?Chat with your personal AI assistant