Python Microproject
Python Microproject
Report On
“Tic-Tac-Toe Game”
Under the subject
‘Programming with Python [22616]’
P
AP
Submitted by
n
tio
Sr. No Enrollment No Name of the student
lu
1 1700100271 Miss. Shinde Mohini Anandrao
So
P
registered then player one won the game. Or if a row of 2s is registered thus player two
AP
won the game. If not, the game is draw. The game ends when there is no more empty
fields in the array (board) to fill or if one of the players wins the game.
diagonally on a 3 x 3 grid.
TE
P
3. Prepare project proposal 06/01/2020 13/01/2020 1. Shinde Mohini
2. Jagtap Sakshi
AP
4. Decide different data 13/01/2020 27/01/2020 1. Shinde Mohini
structures 2. Jagtap Sakshi
n
5. Develop actual program 27/01/2020 17/02/2020
tio 1. Shinde Mohini
code 2. Jagtap Sakshi
6. Debug the program code 17/02/2020 02/03/2020 1. Shinde Mohini
lu
2. Jagtap Sakshi
So
Program code
M
theBoard = {'1': ' ' , '2': ' ' , '3': ' ' ,
'4': ' ' , '5': ' ' , '6': ' ' ,
'7': ' ' , '8': ' ' , '9': ' ' }
board_keys = []
def printBoard(board):
print("\n")
print(' '+board['1'] + ' | ' + board['2'] + ' | ' + board['3'])
print(' ---+---+---')
print(' '+board['4'] + ' | ' + board['5'] + ' | ' + board['6'])
print(' ---+---+---')
print(' '+board['7'] + ' | ' + board['8'] + ' | ' + board['9'])
print("\n")
# Now we'll write the main function which has all the gameplay functionality.
def game():
turn = 'X'
P
count = 0
AP
for i in range(10):
printBoard(theBoard)
n
move=input("It's your turn," + turn + ". Move to which place? ")
tio
#move = input()
lu
So
else:
print("THAT PLACE IS ALREADY FILLED.\nMove to which place?")
continue
SB
# Now we will check if player X or O has won,for every move after 5 moves.
M
if count >= 5:
if theBoard['1'] == theBoard['2'] == theBoard['3'] != ' ': # across the top
printBoard(theBoard)
print("\nGAME OVER.\n\n")
print(" ****** CONGRATULATIONS! " +turn + " YOU WON THE GAME
******\n\n")
break
elif theBoard['4'] == theBoard['5'] == theBoard['6'] != ' ': # across the middle
printBoard(theBoard)
print("\nGAME OVER.\n\n")
print(" ****** CONGRATULATIONS! " +turn + " YOU WON THE GAME
******\n\n")
break
elif theBoard['7'] == theBoard['8'] == theBoard['9'] != ' ': # across the bottom
printBoard(theBoard)
print("\nGAME OVER.\n\n")
print(" ****** CONGRATULATIONS! " +turn + " YOU WON THE GAME
******\n\n")
break
elif theBoard['7'] == theBoard['4'] == theBoard['1'] != ' ': # down the left side
printBoard(theBoard)
print("\nGAME OVER.\n\n")
print(" ****** CONGRATULATIONS! " +turn + " YOU WON THE GAME
******\n\n")
break
P
elif theBoard['8'] == theBoard['5'] == theBoard['2'] != ' ': # down the middle
AP
printBoard(theBoard)
print("\nGAME OVER.\n\n")
print(" ****** CONGRATULATIONS! " +turn + " YOU WON THE GAME
n
******\n\n")
tio
break
elif theBoard['9'] == theBoard['6'] == theBoard['3'] != ' ': # down the right side
lu
printBoard(theBoard)
So
print("\nGAME OVER.\n\n")
print(" ****** CONGRATULATIONS! " +turn + " YOU WON THE GAME
******\n\n")
TE
break
elif theBoard['1'] == theBoard['5'] == theBoard['9'] != ' ': # diagonal
printBoard(theBoard)
SB
print("\nGAME OVER.\n\n")
print(" ****** CONGRATULATIONS! " +turn + " YOU WON THE GAME
M
******\n\n")
break
elif theBoard['7'] == theBoard['5'] == theBoard['3'] != ' ': # diagonal
printBoard(theBoard)
print("\nGAME OVER.\n\n")
print(" ****** CONGRATULATIONS! " +turn + " YOU WON THE GAME
******\n\n")
break
# If neither X nor O wins and the board is full, we'll declare the result as 'tie'.
if count == 9:
print("\nGAME OVER.\n\n")
print("*** IT'S A TIE!! ***\n\n")
break
P
theBoard[key] = " "
AP
game()
n
if __name__ == "__main__":
tio
game()
lu
Output:
So
TE
SB
M
The resources used during the completion of project are mentioned in the below
Sr.no Name of resources Specifications Quantity Remarks
SB
material
1. YouTube MP4-file format, 640 x 1
M
360 pixels
2. Microsoft Word 2010 version 1
P
1. Thisproject can be used as an interesting game for children to pass their free time.
AP
2. The project can be also used to understand the.
3. The project can be used in learning the
n
tio
lu
Subject Teacher
So
Mr. Emekar S. P
TE
SB
M