the script is failing without a useful report

nvictor noagbodjivictor at gmail.com
Sat Sep 4 23:22:39 CEST 2010


hi all,

need your help. i get a traceback that doesn't tell much about the
actual error in my code:

Traceback (most recent call last):
  File ".\eightqueens.py", line 32, in <module>
    generate(n, x, col, up, down)
  File ".\eightqueens.py", line 17, in generate
    else: generate(n, x, col, up, down)
  File ".\eightqueens.py", line 17, in generate
    else: generate(n, x, col, up, down)
  File ".\eightqueens.py", line 17, in generate
    else: generate(n, x, col, up, down)
  File ".\eightqueens.py", line 17, in generate
    else: generate(n, x, col, up, down)
  File ".\eightqueens.py", line 17, in generate
    else: generate(n, x, col, up, down)
  File ".\eightqueens.py", line 17, in generate
    else: generate(n, x, col, up, down)
  File ".\eightqueens.py", line 17, in generate
    else: generate(n, x, col, up, down)
  File ".\eightqueens.py", line 17, in generate
    else: generate(n, x, col, up, down)
  File ".\eightqueens.py", line 17, in generate
    else: generate(n, x, col, up, down)
  File ".\eightqueens.py", line 17, in generate
    else: generate(n, x, col, up, down)

here is the full source:

def generate(n, x, col, up, down):
    for h in range(8):
        # place a queen
        if col[h] and up[n-h] and down[n+h]:
            x[n] = h
            col[h] = False
            up[n-h] = False
            down[n+h] = False
            n += 1

        # 8 queen placed?
        if n == 8: print x
        else: generate(n, x, col, up, down)

        # displace a queen
        n -= 1
        col[h] = True
        up[n-h] = True
        down[n+h] = True


if __name__ == '__main__':
    n = 0
    x = [None]*8
    col = [True]*8
    up = [True]*15
    down = [True]*15
    generate(n, x, col, up, down)


thanks a lot in advance



More information about the Python-list mailing list