info_outline

Solutions will be available when this assignment is resolved, or after a few failing attempts.

Format Board

In this assignment you'll be formatting a simple Tic Tac Toe board:

O  |  O  |  X
--------------
X  |  X  |  O
--------------
O  |  X  |  O

The information of the rows of the board will be kept as strings. Example (considering the board above):

first_row = 'OOX'
second_row = 'XXO'
third_row = 'OXO'

The function that you need to write is format_tic_tac_toe_board that just receives those three rows. It will return the board with those rows filled in correctly from the row information.

Example:

first_row = 'OOX'
second_row = 'XXO'
third_row = 'OXO'

board = format_tic_tac_toe_board(first_row, second_row, third_row)

print(board)  # Result below:
O  |  O  |  X
--------------
X  |  X  |  O
--------------
O  |  X  |  O

Hint: String formatting (the format method) will be really important for this assignment

Test Cases

test format empty board - Run Test

def test_format_empty_board():
    """
    This is the board used in this test:
        X  |  O  |  -
        --------------
        O  |  -  |  -
        --------------
        O  |  -  |  X
    """
    first_row = 'XO-'
    second_row = 'O--'
    third_row = 'O-X'
    expected_board = """
X  |  O  |  -
--------------
O  |  -  |  -
--------------
O  |  -  |  X
"""
    board = format_tic_tac_toe_board(first_row, second_row, third_row)

    assert board == expected_board

test format full board - Run Test

def test_format_full_board():
    """
    This is the board used in this test:
        X  |  O  |  X
        --------------
        O  |  X  |  O
        --------------
        O  |  O  |  X
    """
    first_row = 'XOX'
    second_row = 'OXO'
    third_row = 'OOX'
    expected_board = """
X  |  O  |  X
--------------
O  |  X  |  O
--------------
O  |  O  |  X
"""
    board = format_tic_tac_toe_board(first_row, second_row, third_row)

    assert board == expected_board
# Example. Use it as a base to build your own template. BOARD_TEMPLATE = """ O | O | X -------------- X | X | O -------------- O | X | O """ def format_tic_tac_toe_board(first_row, second_row, third_row): pass