Advertisement
Nenogzar

Untitled

Nov 15th, 2023
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. lines = [input().split() for _ in range(3)]
  2. first_player_win = None
  3.  
  4. for player in ['1', '2']:
  5.     if (any(all(cell == player for cell in line) for line in lines)
  6.             or any(all(line[i] == player for line in lines) for i in range(3))):
  7.         first_player_win = (player == '1')
  8.         break
  9.  
  10. # Check diagonals for both players
  11. for player in ['1', '2']:
  12.     if (all(lines[i][i] == player for i in range(3))
  13.             or all(lines[i][2 - i] == player for i in range(3))):
  14.         first_player_win = (player == '1')
  15.         break
  16.  
  17. if first_player_win is None:
  18.     print("Draw!")
  19. elif first_player_win:
  20.     print("First player won")
  21. else:
  22.     print("Second player won")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement