THE HAPPY VALLEY
SCHOOL
COMPUTER INVESTIGATORY PROJECT
PYTHON
Submitted to: Submitted by:
Mrs. Thejaswini Yashas.M
INTRODUCTION
This project, “Tic Tac Toe” in Python, demonstrates the application of
programming concepts learned in Grade 11. The game of Tic Tac Toe,
also known as Noughts and Crosses, is a simple yet engaging two-player
game where participants alternately mark spaces on a 3x3 grid with their
respective symbols (X and O). The goal is to align three of their symbols
horizontally, vertically, or diagonally to win the game.
The purpose of this project is to implement the rules and logic of Tic
Tac Toe using Python. It involves the use of core programming concepts
such as:
• Conditional Statements: To check game states and declare
results.
• Loops: For managing turns and validating moves.
• Functions: To modularize the code for clarity and reusability.
• Lists: To represent the game board and manage player moves.
This project is designed to enhance problem-solving skills, logical
thinking, and understanding of Python programming fundamentals. By
the end of the project, the user will have an interactive and fully
functional game of Tic Tac Toe that can be played in the console.
ACKNOWLEGMENT
I, Yashas.M, express my heartfelt gratitude to everyone who supported
and guided me in completing this project, Tic Tac Toe in Python
I am immensely thankful to Mrs. Thejaswini, my Computer Science
teacher, for her valuable guidance, encouragement, and insights
throughout the development of this project. Her dedication and teaching
have been instrumental in enhancing my understanding of programming
concepts.
I also extend my sincere thanks to our respected Principal, Mrs. Priya
Simon George, for providing a supportive and inspiring academic
environment that fosters learning and innovation.
Finally, I would like to thank my parents, classmates, and friends for
their continuous motivation and support in completing this project
successfully.
Thank you all for making this journey both enriching and memorable.
INDEX
1. ACKNOWLEGMENT
2. INTRODUCTION
3. SALIENT FEATURES
4. SYSTEM REQUIREMENTS
5. FLOW CHART
6. SOURCE CODE
7. OUTPUT
8. BIBLIOGRAPHY
SALIENT FEATURES
PROGRAM IS USER FRIENDLY
THE PROGRAM IS COMPACT
THE PROGRAM IS RESPONSIVE
EASY TO LEARN AND USE
EXTENSIVE LIBRARIES
OBJECT ORIENTED AND FUNCTIONAL
STRONG COMMUNITY SUPPORT
SYSTEM REQUREMENTS
Main processor : Pentium 111 and above.
Hard disk : 1 GB
RAM : 1GB
Operating system : Windows XP and above.
Compiler: Jupyter, Pycham, Atom etc..,
Language : Python.
FLOWCHART
START
ASK FOR
PLAYER’S
PLAYER’S COMPUTER’S
MOVE MOVE
Get’s its turn Check if
Show the board computer
SOURCE CODE won
Get’s computer turn
# TIC TAC TOE GAME IN PYTHON
Gets players
move Ask to play again
Check for
tie
# Initialize the game board as a list of 9 empty spaces
board = [" "] * 9
# Player symbols
player_marks = {1: "X", 2: "O"}
# Display the Tic Tac Toe board
print("Welcome to Tic Tac Toe!")
print("\n")
print(" | | ")
print(f" 1 | 2 | 3 ")
print("___|___|___")
print(" | | ")
print(f" 4 | 5 | 6 ")
print("___|___|___")
print(" | | ")
print(f" 7 | 8 | 9 ")
print(" | | ")
print("\n")
# Game loop
current_player = 1
game_running = True
while game_running:
# Display the updated board
print("\n")
print(" | | ")
print(f" {board[0]} | {board[1]} | {board[2]} ")
print("___|___|___")
print(" | | ")
print(f" {board[3]} | {board[4]} | {board[5]} ")
print("___|___|___")
print(" | | ")
print(f" {board[6]} | {board[7]} | {board[8]} ")
print(" | | ")
print("\n")
# Get the player's move
valid_move = False
while not valid_move:
try:
move = int(input(f"Player {current_player}
({player_marks[current_player]}), enter your move (1-9): ")) - 1
if 0 <= move <= 8 and board[move] == " ":
board[move] = player_marks[current_player]
valid_move = True
else:
print("Invalid input! Please choose an empty spot
between 1 and 9.")
except ValueError:
print("Please enter a valid number between 1 and 9.")
# Check for a win
winning_combinations = [
[0, 1, 2], # Top row
[3, 4, 5], # Middle row
[6, 7, 8], # Bottom row
[0, 3, 6], # Left column
[1, 4, 7], # Middle column
[2, 5, 8], # Right column
[0, 4, 8], # Diagonal from top-left
[2, 4, 6] # Diagonal from top-right
]
for combo in winning_combinations:
if board[combo[0]] == board[combo[1]] ==
board[combo[2]] == player_marks[current_player]:
print(f"Player {current_player}
({player_marks[current_player]}) wins!")
game_running = False
break
# Check for a draw
if game_running and all(space != " " for space in board):
print("It's a draw!")
game_running = False
# Switch players
current_player = 1 if current_player == 2 else 2
# Final board display
print("\nFinal Board:")
print("\n")
print(" | | ")
print(f" {board[0]} | {board[1]} | {board[2]} ")
print("___|___|___")
print(" | | ")
print(f" {board[3]} | {board[4]} | {board[5]} ")
print("___|___|___")
print(" | | ")
print(f" {board[6]} | {board[7]} | {board[8]} ")
print(" | | ")
print("\n")
print("Thank you for playing Tic Tac Toe!")
OUTPUT
1)If any one of the player wins:
2)If there is a draw:
BIBLOGRAPHY
1.www.google.com
2.www.github.com
3.Slideshare
4.Computer science with python by sumita arora for class 11th
5.Chat-Gpt