Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. square = ['o', '1', '2', '3', '4', '5', '6', '7', '8', '9']
  2. player = 2
  3. playername = None
  4.  
  5.  
  6. def checkwin():
  7. if (square[1] == square[2] == square[3]):
  8. do = False
  9. elif (square[4] == square[5] == square[6]):
  10. do = False
  11. elif (square[7] == square[8] == square[9]):
  12. do = False
  13. elif (square[1] == square[4] == square[7]):
  14. do = False
  15. elif (square[2] == square[5] == square[8]):
  16. do = False
  17. elif (square[3] == square[6] == square[9]):
  18. do = False
  19. elif (square[1] == square[5] == square[9]):
  20. do = False
  21. elif (square[3] == square[5] == square[7]):
  22. do = False
  23. else:
  24. do = True
  25.  
  26.  
  27. def board():
  28. print("+-----------+")
  29. print("| " + square[1] + " | " + square[2] + " | " + square[3] + " |")
  30. print("+-----------+")
  31. print("| " + square[4] + " | " + square[5] + " | " + square[6] + " |")
  32. print("+-----------+")
  33. print("| " + square[7] + " | " + square[8] + " | " + square[9] + " |")
  34. print("+-----------+")
  35.  
  36.  
  37. do = True
  38.  
  39. board()
  40.  
  41. while (do == True):
  42.  
  43. checkwin()
  44. if (player == 1):
  45. player = 2
  46. elif (player == 2):
  47. player = 1
  48.  
  49.  
  50. if (player == 1):
  51. playername = "Player 1"
  52. elif (player == 2):
  53. playername = "Player 2"
  54.  
  55.  
  56. if (player == 1):
  57. mark = 'X'
  58. elif (player == 2):
  59. mark = 'O'
  60.  
  61.  
  62. answer = int(input(playername + " please choose a square: "))
  63.  
  64. if (answer == 1):
  65. square[1] = mark
  66. elif (answer == 2):
  67. square[2] = mark
  68. elif (answer == 3):
  69. square[3] = mark
  70. elif (answer == 4):
  71. square[4] = mark
  72. elif (answer == 5):
  73. square[5] = mark
  74. elif (answer == 6):
  75. square[6] = mark
  76. elif (answer == 7):
  77. square[7] = mark
  78. elif (answer == 8):
  79. square[8] = mark
  80. elif (answer == 9):
  81. square[9] = mark
  82.  
  83. board()
  84.  
  85.  
  86. print(playername + "is the winner!")
  87. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement