[Python] python - how to print Tic Tac Toe game board using for loop

Discussão em 'Python' iniciado por Stack, Abril 2, 2025.

  1. Stack

    Stack Membro Participativo

    I am new to python. Would like to print the game board for the tic tac toe. May I know how to print using for loop?

    [​IMG]

    Here is my code:

    `

    board = {
    1: ' ', 2: ' ', 3: ' ',
    4: ' ', 5: ' ', 6: ' ',
    7: ' ', 8: ' ', 9: ' '
    }
    def printBoard():
    print(board[1] + '|'+ board[2]+'|'+board[3])
    print('-----')
    print(board[4] + '|'+board[5]+'|' + board[6])
    print('-----')
    print(board[7] + '|'+board[8]+'|' + board[9])
    return


    `

    Continue reading...

Compartilhe esta Página