Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy
- line1 = input().split()
- line2 = input().split()
- line3 = input().split()
- matrix = numpy.array([line1, line2, line3])
- cntr_first = 0
- cntr_second = 0
- winner = " "
- if (set(line1) == {"1"} and len(set(line1)) == 1) or (set(line2) == {"1"} and len(set(line2)) == 1) or (set(line3) == {"1"} and len(set(line3)) == 1):
- winner = "First"
- elif (set(line1) == {"2"} and len(set(line1)) == 1) or (set(line2) == {'2'} and len(set(line2)) == 1) or (set(line3) == {"2"} and len(set(line3)) == 1):
- winner = "Second"
- for col in range(len(matrix)):
- for row in range(len(matrix)):
- if matrix[row, col] == "1":
- cntr_first += 1
- elif matrix[row, col] == "2":
- cntr_second += 1
- if cntr_first == 3:
- winner = "First"
- break
- elif cntr_second == 3:
- winner = "Second"
- break
- cntr_first = 0
- cntr_second = 0
- cntr_first = 0
- cntr_second = 0
- for i in range(len(matrix)):
- if matrix[i, i] == "1":
- cntr_first += 1
- elif matrix[i, i] == "2":
- cntr_second += 1
- if cntr_first == 3:
- winner = "First"
- break
- elif cntr_second == 3:
- winner = "Second"
- break
- if matrix[0, 2] == "1" and matrix[1, 1] == "1" and matrix[2, 0] == "1":
- winner = "First"
- elif matrix[0, 2] == "2" and matrix[1, 1] == "2" and matrix[2, 0] == "2":
- winner = "Second"
- if winner == " ":
- print("Draw!")
- else:
- print(f"{winner} player won")
Advertisement
Add Comment
Please, Sign In to add comment