Skip to content

Commit 2267dcf

Browse files
committed
Tic Tac Toe
1 parent 1f25288 commit 2267dcf

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

scripts/Tic-Tac-Toe/main.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
def check(m):
2+
if ( (m[0][0] == m[0][1] == m[0][2] != 0)
3+
or (m[1][0] == m[2][0] == m[0][0] != 0 )
4+
or (m[0][0] == m[1][1] == m[2][2] != 0)
5+
or (m[1][0] == m[1][2] == m[1][2] != 0)
6+
or (m[2][0] == m[2][1] == m[2][2] != 0)
7+
or (m[0][1] == m[1][1] == m[2][1] != 0)
8+
or (m[0][2] == m[1][2] == m[2][2] != 0)
9+
or (m[0][2] == m[1][1] == m[2][0] != 0) ):
10+
return 1
11+
else:
12+
return 0
13+
14+
15+
def display(m):
16+
for i in range(3):
17+
for j in range(3):
18+
print(m[i][j],end = "\t")
19+
print("\n")
20+
21+
22+
a=input("Want to play tic-tac-toe?y/n: ")
23+
if a== "y":
24+
m = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
25+
while True:
26+
i,j= int(input("X: enter row no.")), int(input("enter column no."))
27+
m[i][j]="X"
28+
display(m)
29+
if check(m)== 1:
30+
print("Congratulations you won!")
31+
break
32+
33+
i,j= int(input("O: enter row no.")), int(input("enter column no."))
34+
m[i][j]="O"
35+
display(m)
36+
if check(m)== 1:
37+
print("Congratulations you won!")
38+
break
39+
else:
40+
print("Good Bye!")

scripts/Tic-Tac-Toe/readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Tic Tac Toe with PYTHON
2+
3+
#Steps :
4+
Run - python main.py
5+
Have a fun time!!

0 commit comments

Comments
 (0)