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(a, b): return a + b def read(source, target): with open(source, 'r') as s, open(target, 'w') as t: line1 = s.readline() line2 = s.readline() t.write(add(int(line1), int(line2))) return read('number1.txt', 'number2.txt')

Questions about programming?Chat with your personal AI assistant