-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathX_O_D.py
More file actions
49 lines (44 loc) · 1.05 KB
/
X_O_D.py
File metadata and controls
49 lines (44 loc) · 1.05 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
41
42
43
44
45
46
47
48
49
from typing import List
def checkio(game_result: List[str]) -> str:
g = game_result
s = ['', '', '', ]
l = ['', '']
for i in range(3):
for j in g:
s[i] += j[i]
j = 0
k = 2
for i in g:
l[0] += i[j]
l[1] += i[k]
j += 1
k += -1
total = s + l + g
if "XXX" in total:
return "X"
if 'OOO' in total:
return "O"
return "D"
if __name__ == '__main__':
print("Example:")
print(checkio(["X.O",
"XX.",
"XOO"]))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio([
"X.O",
"XX.",
"XOO"]) == "X", "Xs wins"
assert checkio([
"OO.",
"XOX",
"XOX"]) == "O", "Os wins"
assert checkio([
"OOX",
"XXO",
"OXX"]) == "D", "Draw"
assert checkio([
"O.X",
"XX.",
"XOO"]) == "X", "Xs wins again"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")