I'm quite new to Pyhton, I use it since September in Spyder (Python 3.4). and I would like to create a program that solves a sudoku grid and displays it (in IPython console) during its completion. I hopefully did successfully the sudoku solver and I get a printable grid in output (I only post the printable grid code):
def sudoku_pp(g):
c = g.replace("0","_")
s = ""
l = 0
for i in range(13):
if i % 4 == 0:
for _ in range(25):
s += "-"
else:
k = 9*l
s += "|"
for j in range(9):
s += " "+c[k+j]
if j%3 == 2:
s += " |"
l += 1
s += "\n"
return(s)
where g is a string containing every number line to line, e.g. SUD1 = '530070000600195000098000060800060003400803001700020006060000280000419005000080079'
and
>>>print(sudoku_pp(SUD1))
-------------------------
| 5 3 _ | _ 7 _ | _ _ _ |
| 6 _ _ | 1 9 5 | _ _ _ |
| _ 9 8 | _ _ _ | _ 6 _ |
-------------------------
| 8 _ _ | _ 6 _ | _ _ 3 |
| 4 _ _ | 8 _ 3 | _ _ 1 |
| 7 _ _ | _ 2 _ | _ _ 6 |
-------------------------
| _ 6 _ | _ _ _ | 2 8 _ |
| _ _ _ | 4 1 9 | _ _ 5 |
| _ _ _ | _ 8 _ | _ 7 9 |
-------------------------
My sudoku solver prints a full grid each step, how to erase it entirely and rewrite another one on it?
Thanks a lot and sorry for bad language.