I have txta text input file:
AAA
BBB
CCC
DDD
EEE
FFF,FFF
GGG
I want to copy every kth line of this file into an output txttext file. forFor example, for k=2 it would be:
BBB
DDD
FFF FFF
andAnd for k = 3 it should be
CCC
FFF FFF
thisThis is what I have done so far, I am struggling to find how to identify K in the function. couldCould you please help me?
def ex1 (filen1, filen2, k):
fp1=open(filen1,'r') #open file to read from
fp2=open(filen2,'a') #open file to write to
count=1 #number of lines which have been copied
for line in fp1:
line = next(str(filen1))
list.append(line.strip())
fp1.readline
return list
fp1.close
fp2.close
ex1('Input file.txt', 'Output.txt')