title: Continue writing in same line of file
body: <p>I have opened the file I want to write to using:</p>
  
  <pre><code>data = open('input','a')
  </code></pre>
  
  <p>using a loop, I want to write some words to the file in the same line. And after every loop iteration I want to add a newline character.</p>
  
  <pre><code>while loop:
      for loop:
          /* do something */
          if some_condition:
              data.write(str(tag)+"")
      data.write("\n")
  </code></pre>
  
  <p>My expected output was:</p>
  
  <pre><code>city mountain sky sun
  bay lake sun tree
  </code></pre>
  
  <p>But I'm getting:</p>
  
  <pre><code>city 
  mountain 
  sky 
  sun
  
  bay 
  lake 
  sun 
  tree
  </code></pre>
  
  <p>How can I change my code to get the expected output? Thanks.</p>