R_Milligan3

tic_tac_toe

Jun 12th, 2021
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. Board = [0,1,2,
  2. 3,4,5,
  3. 6,7,8]
  4.  
  5. def Tic_Tac_Toe():
  6. print(Board[0],Board[1],Board[2])
  7. print(Board[3],Board[4],Board[5])
  8. print(Board[6],Board[7],Board[8])
  9. print()
  10.  
  11. def Play_1():
  12. Location = int(input('Player One Choose a Number :'))
  13. if Board[Location]!='X'and Board[Location]!='O':
  14. Board[Location]='X'
  15. else:
  16. print('Already Taken make another Choice')
  17.  
  18. def Play_2():
  19. Location= int(input('Player Two Choose a Number :'))
  20. if Board[Location]!='O' and Board[Location]!='X':
  21. Board[Location]='O'
  22. else:
  23. print('Already Taken make another Choice ')
  24.  
  25. def Check_Winner(X_or_O):
  26. if Board[0]==X_or_O and Board[1]==X_or_O and Board[2]==X_or_O:
  27. return True
  28. if Board[3]==X_or_O and Board[4]==X_or_O and Board[5]==X_or_O:
  29. return True
  30. if Board[6]==X_or_O and Board[7]==X_or_O and Board[8]==X_or_O:
  31. return True
  32. if Board[0]==X_or_O and Board[3]==X_or_O and Board[6]==X_or_O:
  33. return True
  34. if Board[1]==X_or_O and Board[4]==X_or_O and Board[7]==X_or_O:
  35. return True
  36. if Board[2]==X_or_O and Board[5]==X_or_O and Board[8]==X_or_O:
  37. return True
  38. if Board[0]==X_or_O and Board[4]==X_or_O and Board[8]==X_or_O:
  39. return True
  40. if Board[2]==X_or_O and Board[4]==X_or_O and Board[6]==X_or_O:
  41. return True
  42. while True:
  43. Play_1()
  44. Tic_Tac_Toe()
  45. if Check_Winner('X')==True:
  46. print('Player One Wins')
  47. break
  48. Play_2()
  49. Tic_Tac_Toe()
  50. if Check_Winner('O')==True:
  51. print('Player Two Wins')
  52. break
  53.  
Advertisement
Add Comment
Please, Sign In to add comment