Professional Documents
Culture Documents
Msbte Micro Project
Msbte Micro Project
Msbte Micro Project
ON
SUBMITTED BY
Karan sathe.(40)
Under Guidance of
MS. GAVALI.R
Certificate
that we can utilize every time we want to print the updated board in the game.
theBoard = {'7': ' ' , '8': ' ' , '9': ' ' ,
def. printBoard(board):
print('-+-+-')
print('-+-+-')
-+-+-
-+-+-
Now, in the main function, we’ll first take the input from the player and review if the input is a
valid move or not. If the block that the player requests to move to is valid, we’ll fill that block else
we’ll ask the user to pick anothe blocked.
def game():
turn = 'X'
count = 0
for i in range(10):
printBoard(theBoard)
move = input()
theBoard[move] = turn
count += 1
else:
continue
Now, to inspect the winning condition, we’ll review a total of 8 conditions and whichever
player has made the last move, we’ll declare that player a winner. And if no one wins,
we’ll declare ‘tie’.
# Now we will check if player X or O has won,for every move after 5 moves.
If count >= 5:
printBoard(theBoard)
print(“\nGame Over.\n”)
break
printBoard(theBoard)
print(“\nGame Over.\n”)
break
print(“\nGame Over.\n”)
break
printBoard(theBoard)
print(“\nGame Over.\n”)
break
printBoard(theBoard)
print(“\nGame Over.\n”)
break
printBoard(theBoard)
print(“\nGame Over.\n”)
break
printBoard(theBoard)
print(“\nGame Over.\n”)
break
printBoard(theBoard)
print(“\nGame Over.\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”)
Print(“It’s a Tie!!”)
Turn = ‘O’
Else:
Turn = ‘X’
Board_keys = []
Board_keys.append(key)
theBoard[key] = “ “
game()
The tic-tac-toe game is ready to play full python code is given below.
and initialliy it's values will be empty space and then after every move
board_keys = []
board_keys.append(key)
''' We will have to print the updated board after every move in the game and
thus we will make a function in which we'll define the printBoard function
so that we can easily print the board everytime by calling this function. '''
def printBoard(board):
print('-+-+-')
print('-+-+-')
# Now we'll write the main function which has all the gameplay functionality.
def game():
turn = 'X'
count = 0
for i in range(10):
printBoard(theBoard)
move = input()
count += 1
else:
continue
# Now we will check if player X or O has won,for every move after 5 moves.
if count >= 5:
printBoard(theBoard)
print("\nGame Over.\n")
break
printBoard(theBoard)
print("\nGame Over.\n")
break
printBoard(theBoard)
print("\nGame Over.\n")
break
elif theBoard['1'] == theBoard['4'] == theBoard['7'] != ' ': # down the left side
printBoard(theBoard)
print("\nGame Over.\n")
break
printBoard(theBoard)
print("\nGame Over.\n")
break
elif theBoard['3'] == theBoard['6'] == theBoard['9'] != ' ': # down the right side
printBoard(theBoard)
print("\nGame Over.\n")
break
printBoard(theBoard)
print("\nGame Over.\n")
break
printBoard(theBoard)
print("\nGame Over.\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")
print("It's a Tie!!")
if turn =='X':
turn = 'O'
else:
turn = 'X'
game()
if __name__ == "__main__":
game()
the output of the above python program the game is working and a working screenshot
of this game is given below.
After creating this game, we can get a pretty exact idea about dictionaries in python, how to access
dictionaries, how to iterate over dictionaries, for loop, if-else conditions, and functions in python.
5.CONCLUSION
a two-player tic-tac-toe game, which we can play on the command line.
Python is generally utilized for creating websites and software, task automation, data
analysis, and data visualization.