[Tutor] Sudoku

myles broomes mylesbroomes at hotmail.co.uk
Sun Sep 23 12:08:06 CEST 2012


I'm currently coding a Sudoku clone but I'm having trouble displaying the board: # Sudoku
# Sudoku is a logic-based number-placement puzzle
# The objective is to fill a 9×9 grid with digits so that each column, each row, and each of the nine 3×3 sub-grids that compose the grid contains all of the digits from 1 to 9import randomdef new_board():
    """Creates the game board. """
    board=[]
    for i in range(9):
        column=[]
        for j in range(9):
            column.append(i)
        board.append(column)
    return boarddef display_board(board):
    """Display game board on screen."""
    for i in range(9):
        for j in range(9):
            rand_num=random.randint(0,9)
            if rand_num not in board[i]:
                board[i][j]=rand_num
            else:
                board[i][j]=' '
            print(board[i][j],"|")# assign the new board to a variable and display it on the screen
game_board=new_board()
display_board(game_board)
I cant think of a way to get each column in the for loop (board[i]) to print side by side. Any help would be much appreciated. Myles. 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120923/2351b9a8/attachment.html>


More information about the Tutor mailing list