SIZ TUTORIAL | Creation Of Tic-Tac-Toe Game With Python in 15 lines | 20% Beneficiary to @sIz-official
Introduction
Hello Guys Assalam-o-Alaikum,Hope you all guys are fine in this Covid circumstances, Today I will tell you about very interesting
game which everybody has at least one time played in their life its name is Tic-tac-Toe game but the twist is that we will code this game in python programming lets start coding and its interpretation.
![tic tac toe.jpg](https://steemitimages.com/640x0/https://cdn.steemitimages.com/DQmVL4BPTxKA95JopyL26TSn5LGum2KXydnXA8KY6nFEruu/tic%20tac%20toe.jpg)
Achievements | Links |
---|---|
Achievement # 1 | Link |
Achievement # 2 | Link |
Step#1
First we are taking input from user to input elements of row 1 to row 3. Note that input must be "X" and "O" remember it's case sensitive.pattern=[]
for i in range(1,4):
print('Enter state',i,'for row',str(i),'separated by commas:',end=' ')
i=input()
pattern.append(i.split(","))
Step#2:It will print elements("O" or "X") in a matrix form which I will show you in output. It follows the complete pattern as play tic tac toe game on paper.
for row in pattern:
print('|',end='\t')
for state in row:
print(state,end='\t')
print('|')
Step#3
This is our final step it will check whether our rows elements are same, diagonally all elements are same or columns wise elements match. if "X" win it will display result in the end "X" or if "O" wins it will show result "O"if (pattern[0][0] == pattern[0][1] == pattern[0][2]) and (pattern[0][0]=='O'or'X'):print(pattern[0][0])
elif (pattern[1][0] == pattern[1][1] == pattern[1][2]) and (pattern[1][0]=='O'or'X'):print(pattern[1][0])
elif (pattern[2][0] == pattern[2][1] == pattern[2][2]) and (pattern[2][0]=='O'or'X'):print(pattern[2][0])
elif (pattern[0][0] == pattern[1][0] == pattern[2][0]) and (pattern[0][0]=='O'or'X'):print(pattern[0][0])
elif (pattern[0][1] == pattern[1][1] == pattern[2][1]) and (pattern[0][1]=='O'or'X'):print(pattern[0][1])
elif (pattern[0][2] == pattern[1][2] == pattern[2][2]) and (pattern[0][2]=='O'or'X'):print(pattern[0][2])
elif (pattern[0][0] == pattern[1][1] == pattern[2][2]) and (pattern[0][0]=='O'or'X'):print(pattern[0][0])
elif (pattern[0][2] == pattern[1][1] == pattern[2][0]) and (pattern[0][2]=='O'or'X'):print(pattern[0][2])
else:
print(' ')
Output
Enter state 1 for row 1 separated by commas: O,X,X
Enter state 2 for row 2 separated by commas: X,X,O
Enter state 3 for row 3 separated by commas: O,X,O
| O X X |
| X X O |
| O X O |
X
#club5050 😀
Good one Post dear friend you make a very good post thanks for sharing a good information with us my best wishes for you.
Regards, Faran Nabeel
Your work is out standing.... I like it very much.. so keep it up , my best wishes for you
Thankyou so much means alot.💫
Very informative and amazing post......thanks for sharing such an exciting tutorial .
Keep good work!
good post dear friend
Keep it up bro
Wow its super tutorial
Nice skill u got there