Training and Development in Banking Sector
Training and Development in Banking Sector
ABSTRACT
INTRODUCTION
Tic-Tac-Toe is a timeless and popular game that combines simplicity with strategy,
often played on a 3x3 grid. Each player takes turns placing either an "X" or an "O" in
an empty square, with the aim of being the first to form a line of three matching
symbols in a row, either horizontally, vertically, or diagonally. While the game’s
rules are straightforward, it offers a surprising depth of strategy as players anticipate
each other’s moves, try to block their opponent’s winning chances, and create
opportunities for themselves. If all squares are filled without a winner, the game ends
in a draw. Tic-Tac-Toe is enjoyed by people of all ages and can be a fun way to
challenge both friends and family, making it a great pastime that can be played
quickly and anywhere.
Tic-Tac-Toe is a classic two-player game played on a 3x3 grid where players take
turns marking a square with either an "X" or an "O". The objective is to align three of
your marks in a row, either horizontally, vertically, or diagonally, before your
opponent does. The game ends when one player achieves this goal, or when all the
squares are filled, resulting in a draw if no one wins. It’s a simple yet strategic game
that’s easy to learn and fun for players of all ages
BRIEF DESCRIPTION
A two-player tic-tac-toe game, which we can play on the command line. Initially,
we'll make a blank game board and then we'll take inputs from the players and we'll
check for the winning situation if the entire board gets loaded and no one wins, we'll
declare the result as "tie" and ask users if they want to restart the game.
We will create this game using Python 3, so make sure you have it installed on your
laptop/computer and we are good to go.
The board is numbered like the keyboard's number pad. And thus, a player can make
their action on the game board by entering the number from the keyboard number
pad.
CODING
Utilize the dictionary to make our game board. A dictionary is a primitive data type in
python that kept data in "key: value" format. And thus, we'll make a dictionary of
length 9 and each key will illustrate a block on the board and its related value will
illustrate the move made by a player, and we'll make a function
PrintBoard ()
That we can utilize every time we want to print the updated board in the game.
def. printBoardtboard);
print(board["7"]+-board[8] board[])
print('---
print(board[4]+"-board[5]-board['6'])
print()
print(hoand['1']+board['2']+bound['3'])
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 (the Board)
printf ("It's your turn." +turn +".Move to which place?")
move input()
if the Board[move]==’’;
the board [move] = turn
count+=1
else;
print("That place is already filled. \nMove to which place?")
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
printBoard(the Board)
break
printBoard(theBoard)
print("\nGame Over.\n")
print(" +turn"won)
break
printBoard(theBoard)
print("\nGame Over.\n").
break
printBoard (theBoard)
print("\nGame Over.\n")
break
printBoard(the Board)
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 "tic'..
A.C.S.’S. DIPLOMA IN ENGG & TECH, ASHTI Page | 7
TIC-TAC-TOE GAME
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.
board_keys = []
""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(board['7'] + ''+ board['8'] + '' + board['9'])
print('-+-+-')
print(board['4'] + '"' + board['5']+'' + board['6'])
print('-+-+-')
print(board['1'] + ''+ board['2'] + '' + board['3'])
# 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)
print("It's your turn," + turn + ".Move to which place?")
move = input()
if theBoard[move] == '":
theBoard[move] = turn
count += 1
else:
continue
# Now we will check if player X or O has won, for every move after 5 moves.
if count >= 5:
break
elif the Board['1'] == theBoard['4'] == theBoard['7'] != '': # down the left side
printBoard(theBoard)
print("\nGame Over.\n")
print(" ****"+turn + "won. ****")
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!!")
game()
if_name_==”_main_”:
game()
OUTPUT
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.
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.
In a Tic Tac Toe game, the conclusion occurs when either one player achieves three of
their marks in a row, column, or diagonal, resulting in a win for that player, or when
the board fills up with no winner, leading to a draw. If Player X or Player O manages
to align their marks successfully, the game ends with a declaration of their victory. If
all nine squares are filled without anyone winning, the game concludes as a tie. This
simple structure makes for a quick and engaging game, often played multiple times to
determine a series winner.
REFERENCES
17