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 add_file(source, target): with open(source) as source_file, open(target, 'w') as target_file: for line in source_file: target_file.write(str(sum(map(int, line.split()))) + '\n') add_file('source.txt', 'target.txt')

Questions about programming?Chat with your personal AI assistant