-
Notifications
You must be signed in to change notification settings - Fork 2
/
Code
56 lines (49 loc) · 1.03 KB
/
Code
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
x=set()
y=set()
b=[x,y]
win_con=({0,1,2},{3,4,5},{6,7,8},{0,4,8},{2,4,6},{0,3,6},{1,4,7},{2,5,8})
a=['']*10
def clear():
for i in range(0,10):
a[i]=i
x.clear()
y.clear()
def grid():
for x in range(0,3):
for y in range(0,3):
if y==2:
print(a[3*x+y],end='')
else:
print(a[3*x+y],'|',end='')
if x!=2:
print('\n--+--+--')
def win():
for i in range(0,2):
if b[i] in win_con:
return 1
return 0
def play():
i=0
clear()
while i<9:
grid()
t=int(input("\nPlayer 1 enters"))
a[t]='X'
x.add(t)
if win()==1:
print('Player 1 wins')
break
grid()
t=int(input("\nPlayer 2 enters"))
a[t]='0'
y.add(t)
if win()==1:
print('Player 2 wins')
break
i+=2
if win()==0:
print("Tie")
k=input('Play again?')
if k=='y':
play()
play()