forked from metafy-social/python-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (35 loc) · 1.08 KB
/
Copy pathmain.py
File metadata and controls
40 lines (35 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def check(m):
if ( (m[0][0] == m[0][1] == m[0][2] != 0)
or (m[1][0] == m[2][0] == m[0][0] != 0 )
or (m[0][0] == m[1][1] == m[2][2] != 0)
or (m[1][0] == m[1][2] == m[1][2] != 0)
or (m[2][0] == m[2][1] == m[2][2] != 0)
or (m[0][1] == m[1][1] == m[2][1] != 0)
or (m[0][2] == m[1][2] == m[2][2] != 0)
or (m[0][2] == m[1][1] == m[2][0] != 0) ):
return 1
else:
return 0
def display(m):
for i in range(3):
for j in range(3):
print(m[i][j],end = "\t")
print("\n")
a=input("Want to play tic-tac-toe?y/n: ")
if a== "y":
m = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
while True:
i,j= int(input("X: enter row no.")), int(input("enter column no."))
m[i][j]="X"
display(m)
if check(m)== 1:
print("Congratulations you won!")
break
i,j= int(input("O: enter row no.")), int(input("enter column no."))
m[i][j]="O"
display(m)
if check(m)== 1:
print("Congratulations you won!")
break
else:
print("Good Bye!")