title: Backtracking in Python [2]
body: <p>I have just came up with this simple Python algorithm for generating all the possible permutations from 1 to n, but it does not seem to work. Here is the code:</p>
  
  <pre><code>def main ():
      n = 3
      x = [0] * 4
      k = 1
      while k:
          ok = True
          while x[k] &lt; n and ok:
              for i in range (0,k-1):
                  if x[i] == x[k]:
                      ok = False
                  if ok:
                      x[k] += 1
              if x[k] &lt; n:
                  if k == n:
                      print x
                  else:
                      k+=1
                      x[k] = 0
              else:
                  k-=1
  main()
  </code></pre>
  
  <p>When I run it, nothing happens. Can you please help me? I am also new to Python</p>