SIZ TUTORIAL | Creation Of Tic-Tac-Toe Game With Python in 15 lines | 20% Beneficiary to @sIz-official

in Steem Infinity Zone3 years ago (edited)

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

AchievementsLinks
Achievement # 1Link
Achievement # 2Link

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

Conclusion

It is a quite interesting let you guys run code if you face any problem you can ask in comment.

Sort:  
 3 years ago 

#club5050 😀

 3 years ago 

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

 3 years ago 

Your work is out standing.... I like it very much.. so keep it up , my best wishes for you

Thankyou so much means alot.💫

 3 years ago 

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

 3 years ago 

Nice skill u got there

Coin Marketplace

STEEM 0.18
TRX 0.14
JST 0.030
BTC 60238.27
ETH 3215.90
USDT 1.00
SBD 2.46