Advertisement
usmiwka80

5.Tic-Tac-Toe

Oct 11th, 2024
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.06 KB | Software | 0 0
  1. sequence_numbers_1 = input().split()
  2. sequence_numbers_2 = input().split()
  3. sequence_numbers_3 = input().split()
  4.  
  5. line_1 = []
  6. line_2 = []
  7. line_3 = []
  8.  
  9. for index in range(len(sequence_numbers_1)):
  10.     if sequence_numbers_1[index].isdigit():
  11.         line_1.append(int(sequence_numbers_1[index]))
  12.  
  13. for index in range(len(sequence_numbers_2)):
  14.     if sequence_numbers_2[index].isdigit():
  15.         line_2.append(int(sequence_numbers_2[index]))
  16.  
  17. for index in range(len(sequence_numbers_3)):
  18.     if sequence_numbers_3[index].isdigit():
  19.         line_3.append(int(sequence_numbers_3[index]))
  20.  
  21. # horizontal lines
  22. if line_1[0] == line_1[1] and line_1[0] == line_1[2]:
  23.     if line_1[0] == 1:
  24.         print("First player won")
  25.     elif line_2[0] == 2:
  26.         print("Second player won")
  27. elif line_2[0] == line_2[1] and line_2[0] == line_2[2]:
  28.     if line_2[0] == 1:
  29.         print("First player won")
  30.     elif line_2[0] == 2:
  31.         print("Second player won")
  32. elif line_3[0] == line_3[1] and line_3[0] == line_3[2]:
  33.     if line_3[0] == 1:
  34.         print("First player won")
  35.     elif line_3[0] == 2:
  36.         print("Second player won")
  37.  
  38. # vertical lines
  39. elif line_1[0] == line_2[0] and line_1[0] == line_3[0]:
  40.     if line_1[0] == 1:
  41.         print("First player won")
  42.     elif line_1[0] == 2:
  43.         print("Second player won")
  44. elif line_1[1] == line_2[1] and line_1[1] == line_3[1]:
  45.     if line_1[1] == 1:
  46.         print("First player won")
  47.     elif line_1[1] == 2:
  48.         print("Second player won")
  49. elif line_1[2] == line_2[2] and line_1[2] == line_3[2]:
  50.     if line_1[2] == 1:
  51.         print("First player won")
  52.     elif line_1[2] == 2:
  53.         print("Second player won")
  54.  
  55. # angle lines
  56. elif line_1[0] == line_2[1] and line_1[0] == line_3[2]:
  57.     if line_1[0] == 1:
  58.         print("First player won")
  59.     elif line_1[0] == 2:
  60.         print("Second player won")
  61. elif line_1[2] == line_2[1] and line_1[2] == line_3[0]:
  62.     if line_1[2] == 1:
  63.         print("First player won")
  64.     elif line_1[2] == 2:
  65.         print("Second player won")
  66. else:
  67.     print("Draw!")
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement