What are the relevant packages that we need to import to draw this?
Jun 26, 2019 in Python 9,985 views

## 3 answers to this question.

Following is a code to draw a tic tac toe board in python.

```def draw_board():
v = '|    |    |    |'
h = ' ____ ____ ____ '
for i in range(0,10):
if i%3==0:
print(h)
else:
print(v)
draw_board()```

Hope this will help!

Thank!

• 3,230 points
Respected sir ,

your code is very simple and easy to understand but i have one problem how to put 'X' and 'o' in this board using this code . please suggest me

Hey,

You can try this:

```   def is_game_over():
for a, b, c in WIN_COMBINATIONS:
if board[a] == board[b] == board[c]:
print("Player {0} wins!\n".format(board[a]))
print("Congratulations!\n")
return True
if 9 == sum((pos == 'X' or pos == 'O') for pos in board):
print("The game ends in a tie\n")
return True

for player in 'XO' * 9:
draw()
if is_game_over():
break
board[choose_number()] = player
print()

while True:
tic_tac_toe()
if input("Play again (y/n)\n") != "y":
break```

I hope this will help.

I also want to know the answer of this question.

answered Jun 25, 2020 by anonymous

Hi, @There,

Did you try the above-given solution? I hope those will help you out for sure.

def printTable():
for i in range(1,10):
print(" ",end=' ')
if(i%3==0 and i!=9):
print("\n",'-'*8)
elif i!=9:
print('|',end=' ')

Whole Game:
Used List for storing O and X.
Index as position from 1 to 9

1 | 2 | 3
--------
4 | 5 | 6
--------
7 | 8 | 9

P.S No package is required to be imported
Code available at
https://github.com/SumitNagpal94/MCA/tree/master/Python
answered Oct 11, 2020 by Sumit Nagpal

## How to add a new line in Python?

You can use '\n' for a next ...READ MORE

## How to calculate square root of a number in python?

calculate square root in python >>> import math ...READ MORE

+1 vote

## How to print first character of each word in upper case of a string in Python

class Solution:     def firstAlphabet(self, s):             self.s=s              k=''              k=k+s              for i in range(len(s)):                     if ...READ MORE

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

## Lowercase in Python

You can simply the built-in function in ...READ MORE