Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
check all lines solution in Clear category for Xs and Os Referee by akaka
from typing import List
def checkio(game_result: List[str]) -> str:
for col in range(0,3):#verticals
game_result.append(game_result[0][col]+game_result[1][col]+game_result[2][col])
game_result.append(game_result[0][2]+game_result[1][1]+game_result[2][0])#diagonals
game_result.append(game_result[0][0]+game_result[1][1]+game_result[2][2])#diagonals
#result
for line in game_result:
if all([c == "X" for c in line]):
return "X"
elif all([c == "O" for c in line]):
return "O"
else:
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!")
July 20, 2018