title: Python Output Ambiguity
body: <p>So I have written the following code to generate <a href="http://en.wikipedia.org/wiki/Combination" rel="nofollow">combinations (n choose k)</a>:</p>
  
  <pre><code>#!/usr/bin/env python3
  
  combinations = []
  used = []
  
  def init(num):
      for i in range(0, num+1):
          combinations.append(0)
          used.append(0)
  
  def printSolution(coef):
      for i in range(1, coef+1):
          print(combinations[i], " ", end=' ')
      print("\n")
  
  def generateCombinations(which, what, num, coef):
      combinations[which] = what
      used[what] = 1
  
      if which == coef:
          printSolution(coef)
      else:
          for next in range(what+1, num+1):
              if not used[next]:
                  generateCombinations(which+1, next, num, coef)
  
      used[what] = 0
  
  n = int(input("Give n:"))
  k = int(input("Give k:"))
  
  if k &lt;= n:
      init(n)
      for i in range(1, n+1):
          generateCombinations(1, i, n, k)
  
  input()
  </code></pre>
  
  <p>The problem with it is that when it outputs the text, instead of writing one line after another like this:</p>
  
  <pre><code>Give n:4
  Give k:3
  1 2 3
  1 2 4
  1 3 4
  2 3 4
  </code></pre>
  
  <p>It actually outputs it like this:</p>
  
  <pre><code>Give n:4
  Give k:3
  1 2 3
  
  1 2 4
  
  1 3 4
  
  2 3 4
  </code></pre>
  
  <p>My question is, why does that actually happen, and how to fix it? I must say that I'm new to python, so don't be harsh on me. Thank you in advance.</p>