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.
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 😀
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
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
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Your work is out standing.... I like it very much.. so keep it up , my best wishes for you
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thankyou so much means alot.💫
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Very informative and amazing post......thanks for sharing such an exciting tutorial .
Keep good work!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
good post dear friend
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Keep it up bro
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Wow its super tutorial
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Nice skill u got there
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit