'Complete the PrintTicTacToe function with parameters horiz_char and vert_char that prints a tic-tac-toe board with the characters as follows

Complete the PrintTicTacToe function with parameters horiz_char and vert_char that prints a tic-tac-toe board with the characters as follows.

def print_tic_tac_toe(horiz_char, vert_char):
    # FIXME: complete function to print game board
    return

Ex: print_tic_tac_toe('~', '!') prints:

Screen shot of the questions and example output



Solution 1:[1]

def print_tic_tac_toe(horiz_char, vert_char):
    a = 'x ' + vert_char + ' x ' + vert_char + ' x'
    b = ((horiz_char + ' ')*4 + horiz_char)
    print((a +'\n' + b+'\n') * 2 + a)
print_tic_tac_toe('~', '!')

Solution 2:[2]

You could also solve this problem with loops, but I think that this is the simplest solution:

def print_tic_tac_toe(horiz_char, vert_char):
    a = "x" + vert_char + "x" + vert_char + "x"
    b = horiz_char*5
    print((a+"\n"+b+"\n")*2+a)
    
print_tic_tac_toe('~', '!')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steven Evans
Solution 2