viligen

tic_tac_toe_1

Oct 5th, 2021
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. line1 = input().split()
  2. line2 = input().split()
  3. line3 = input().split()
  4.  
  5. winner = " "
  6.  
  7.  
  8. 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):
  9.     winner = "First"
  10. 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):
  11.     winner = "Second"
  12.  
  13. for col in range(len(line2)):
  14.     if line1[col] == line2[col] == line3[col] == "1":
  15.         winner = "First"
  16.         break
  17.     elif line1[col] == line2[col] == line3[col] == "2":
  18.         winner = "Second"
  19.         break
  20.  
  21. col = 0
  22. if line1[col] == line2[col + 1] == line3[col + 2] == "1" or line1[col + 2] == line2[col + 1] == line3[col] == "1":
  23.     winner = "First"
  24. elif line1[col] == line2[col + 1] == line3[col + 2] == "2" or line1[col + 2] == line2[col + 1] == line3[col] == "2":
  25.     winner = "Second"
  26.    
  27. if winner == " ":
  28.     print("Draw!")
  29. else:
  30.     print(f"{winner} player won")
  31.  
Advertisement
Add Comment
Please, Sign In to add comment