Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Xs and Os Referee by Jakob_Wolitzki
def checkio(game_result):
if game_result[0][0] == game_result[0][1] == game_result [0][2] and game_result[0][0] != ("."):
if game_result[0][0] == "X":
print ("X")
return "X"
else:
print ("O")
return "O"
elif game_result[1][0] == game_result[1][1] == game_result [1][2] and game_result[1][0] != ("."):
if game_result[1][0] == "X":
print("X")
return "X"
else:
print("O")
return "O"
elif game_result[2][0] == game_result[2][1] == game_result [2][2] and game_result[2][0] != ("."):
if game_result[2][0] == "X":
print("X")
return "X"
else:
print("O")
return "O"
elif game_result[0][0] == game_result[1][0] == game_result [2][0] and game_result[0][0] != ("."):
if game_result[0][0] == "X":
print("X")
return "X"
else:
print("O")
return "O"
elif game_result[0][1] == game_result[1][1] == game_result [2][1] and game_result[0][1] != ("."):
if game_result[0][1] == "X":
print("X")
return "X"
else:
print("O")
return "O"
elif game_result[0][2] == game_result[1][2] == game_result [2][2] and game_result[0][2] != ("."):
if game_result[0][2] == "X":
print("X")
return "X"
else:
print("O")
return "O"
elif game_result[0][0] == game_result[1][1] == game_result[2][2] and game_result[0][0] != ("."):
if game_result[0][0] == "X":
print("X")
return "X"
else:
print("O")
return "O"
elif game_result[2][0] == game_result[1][1] == game_result[0][2] and game_result[0][2] != ("."):
if game_result[0][2] == "X":
print("X")
return "X"
else:
print("O")
return "O"
else:
print ("D")
return "D"
if __name__ == '__main__':
#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!")
Oct. 18, 2017