Exemplo n.º 1
0
def enterRow(sudoku):
    val = raw_input("\nEnter row, of the form: \"1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]\"\nPut a 0 for a blank square.\n\n")

    if len(val) != 31:
        print "\nIncorrect format. Here is an example: "
        print "    1 = [2, 5, 0, 0, 0, 6, 7, 8, 0] will put those values in the first row"

        return

    try:
        rowInd = int(val[0:1]) - 1

        nums = map(int, val[5:-1].split(","))

    except ValueError:
        print "\nIncorrect format ERROR. Here is an example: "
        print "    1 = [2, 5, 0, 0, 0, 6, 7, 8, 0] will put those values in the first row"

        return

    row = []

    for col in range(9):
        row.append(nums[col])

    sudoku[rowInd] = row

    main.printSudoku(sudoku)
Exemplo n.º 2
0
def enterValue(sudoku):
    print "0 will clear the cell, 1-9 will insert a number"
    val = raw_input("\nEnter a coordinate and a value of the form \"[row][col] = number\":\n\n")

    if len(val) != 10:
        print "\nIncorrect format. Here is an example: "
        print "    [1][9] = 5 will put a 5 in the very bottom left corner"

        return

    try:
        row = int(val[1:2])
        row -= 1

        col = int(val[4:5])
        col -= 1

        num = int(val[-1])

    except ValueError:
        print "\nIncorrect format. Here is an example: "
        print "    [1][9] = 5 will put a 5 in the very bottom left corner"

    sudoku[row][col] = num
    main.printSudoku(sudoku)
Exemplo n.º 3
0
def enterColumn(sudoku):
    val = raw_input("\nEnter column, of the form: \"colNum = [1, 2, ... , 9]\"\nPut a 0 for a blank square.\n\n")

    if len(val) != 31:
        print "\nIncorrect format. Here is an example: "
        print "    1 = [2, 5, 0, 0, 0, 6, 7, 8, 0] will put those values in the first column"

        return

    try:
        colInd = int(val[0:1]) - 1

        nums = map(int, val[5:-1].split(","))

    except ValueError:
        print "\nIncorrect format ERROR. Here is an example: "
        print "    1 = [2, 5, 0, 0, 0, 6, 7, 8, 0] will put those values in the first row"

        return

    col = []

    for row in range(9):
        col.append(nums[row])


    for row in range(9):
        sudoku[row][colInd] = col[row]

    main.printSudoku(sudoku)
Exemplo n.º 4
0
def clearSudoku(sudoku):
    for y in range(9):
        for x in range(9):
            sudoku[x][y] = 0

    main.printSudoku(sudoku)