title: How to return every kth element of input file in output file?
body: <p>I have a text input file:</p>
  <pre><code>AAA
  BBB
  CCC
  DDD
  EEE
  FFF,FFF
  GGG
  </code></pre>
  <p>I want to copy every kth line of this file into an output text file. For example, for k=2 it would be:</p>
  <pre><code>BBB
  DDD
  FFF FFF
  </code></pre>
  <p>And for <code>k = 3</code> it should be</p>
  <pre><code>CCC
  FFF FFF
  </code></pre>
  <p>This is what I have done so far, I am struggling to find how to identify K in the function. Could you please help me?</p>
  <pre><code>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')
  </code></pre>