Ever wondered how a classic game like Tic-Tac-Toe is built from scratch? In this video, we’ll dive into the exciting world of Python programming and guide you step-by-step to create your own two-player Tic-Tac-Toe game.
👨💻 What you'll learn:
• Handling user input
• Working with 2D lists
• Using loops and conditionals
• Implementing game logic and win conditions
Whether you're new to coding or just looking to sharpen your skills, this challenge is the perfect hands-on project to boost your Python confidence!
🚀 Try it yourself in Google Colab:
1. Visit Google Colab
2. Create a new notebook
3. Copy & paste the code below
4. Hit Run and start playing!
📎 Attached below is the Python code for a Two-Player Tic-Tac-Toe game.
This script allows users to play the classic game directly in the console, making it a fun and interactive way to practice core Python concepts like loops, conditionals, user input, and list manipulation.
🖥️ You can run the code in any Python environment or copy it into Google Colab for easy access and testing.
PYTHON CODE AS FOLLOWS BELOW👇:
TIC-TAC-TOE GAME (Two Player Version)
def print_board(board):
print("\n")
for row in board:
print(" | ".join(row))
print("-" * 9)
print("\n")
def check_winner(board, player):
Check rows, columns, and diagonals
for i in range(3):
if all([cell == player for cell in board[i]]) or all([board[j][i] == player for j in range(3)]):
return True
if all([board[i][i] == player for i in range(3)]) or all([board[i][2-i] == player for i in range(3)]):
return True
return False
def is_full(board):
return all([cell in ['X', 'O'] for row in board for cell in row])
def tic_tac_toe():
board = [["1", "2", "3"],
["4", "5", "6"],
["7", "8", "9"]]
current_player = "X"
print("Welcome to Tic-Tac-Toe!")
print("Player X and Player O will take turns.\n")
while True:
print_board(board)
move = input(f"Player {current_player}, enter the number of the cell (1-9): ")
if not move.isdigit() or int(move) not in range(1, 10):
print("Invalid input. Try again.")
continue
move = int(move)
row = (move - 1) // 3
col = (move - 1) % 3
if board[row][col] in ['X', 'O']:
print("Cell already taken. Choose another.")
continue
board[row][col] = current_player
if check_winner(board, current_player):
print_board(board)
print(f"🎉 Player {current_player} wins!")
break
if is_full(board):
print_board(board)
print("It's a draw!")
break
current_player = "O" if current_player == "X" else "X"
Run the game
tic_tac_toe()
Let the battle of Xs and Os begin!
#python #TicTacToe #CodingChallenge #beginnerprojects #programming
On this page of the site you can watch the video online Build a Tic Tac Toe Game in Python Beginner Coding Challenge! with a duration of hours minute second in good quality, which was uploaded by the user Future Grid Tech 03 June 2025, share the link with friends and acquaintances, this video has already been watched 76 times on youtube and it was liked by 2 viewers. Enjoy your viewing!