MCC Public School Chetpet, Chennai - 600031: Computer Science Investigatory Project 2022 - 2023
MCC Public School Chetpet, Chennai - 600031: Computer Science Investigatory Project 2022 - 2023
COMPUTER SCIENCE
INVESTIGATORY PROJECT
2022 - 2023
TIC-TAC-TOE
Submitted by
Surya
1
S.NO TABLE OF CONTENTS PAGE NO
1 CERTIFICATE 1
2 ACKNOWLEDGMENT 2
3 AIM 3
4 INTRODUCTION 3
5 SOFTWARE REQUIRED 4
6 PROGRAM CODE 5
7 OUTPUT 10
8 CONCLUTION 11
9 BIBLIOGRAPHY 12
2
BONAFIDE CERTIFICATE
This 1s to certify that Surya of class XI A from MCC
PUBLIC SCHOOL, has successfully completed the
Computer Science Investigatory Project on the topic
TIC-TAC-TOE. Under the guidance of
Ms.Mohanapriya during the academic year 2022-2023
in partial fulfilment of Computer Science practical
examination conducted by AISSCE, Delhi.
School seal:
3
ACKNOWLEDGMENT
My sincere compliments and gratitude to our
Computer Science teacher Ms. Mohanapriya for her
valuable suggestions, guidance, and encouragement in
completing the project.
4
AIM:
To generate a TIC-TAC-TOE game in Python,
without using Pygame in IDLE or Visual Code.
INTRODUCTION:
By using Python we have created the
game TIC-TAC-TOE, using def function. We used
simple programs in order to complete the game without
Pygame.
SOFTWARE REQUIREMENTS:
1. Python
2. Visual Studio Code or IDLE
PROGRAM CODE
5
board = [" " for x in range(9)]
def print_board():
row1 = "| {} | {} | {} |".format(board[0], board[1],
board[2])
row2 = "| {} | {} | {} |".format(board[3], board[4],
board[5])
row3 = "| {} | {} | {} |".format(board[6], board[7],
board[8])
print()
print(row1)
print(row2)
print(row3)
print()
def player_move(icon):
if icon == "X":
number=1
elif icon == "O":
number = 2
print("Your turn player {}".format(number))
choice = int(input("Enter your move (1-9): ").strip())
6
if board[choice - 1] == " ":
board[choice - 1] = icon
else:
print()
print("That space is already taken!")
def is_victory(icon):
if (board[0] == icon and board[1] == icon and
board[2] == icon) or \
(board[3] == icon and board[4] == icon and
board[5] == icon) or \
(board[6] == icon and board[7] == icon and
board[8] == icon) or \
(board[0] == icon and board[3] == icon and
board[6] == icon) or \
(board[1] == icon and board[4] == icon and
board[7] == icon) or \
(board[2] == icon and board[5] == icon and
board[8] == icon) or \
7
return True
else:
return False
def is_draw():
if " " not in board:
return True
else:
return False
while True:
print_board()
player_move("X")
print_board()
if is_victory("X"):
print("X wins! Congratulations!")
break
elif is_draw():
print("It's a draw!")
break
player_move("O")
8
if is_victory("O"):
print_board()
print("O wins! Congratulations!")
break
elif is_draw():
print("It's a draw!")
break
9
OUTPUT:
10
C
ONCLUSION
11
The TIC-TAC-TOE game was successfully
executed with simple program and the output
was verified.
BIBLIOGRAPHY
Source:
Chat GPT
12