ZEdKasat

TicTacToe Python

Jul 18th, 2021 (edited)
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. def printboard(board):
  2.     print(board[1] + " | " + board[2] + " | " + board[3])
  3.     print("- + - + -")
  4.     print(board[4] + " | " + board[5] + " | " + board[6])
  5.     print("- + - + -")
  6.     print(board[7] + " | " + board[8] + " | " + board[9])
  7.  
  8. def get_input(turn, board):
  9.     while True:
  10.         print(turn+ "'s turn")
  11.         position = input("Enter the position you want to play. ")
  12.  
  13.         if not position.isdigit():
  14.             print("Please enter a valid number")
  15.         elif not 1 <= position <= 9:
  16.             print("Enter the number in valid range")
  17.         elif not board.isdigit():
  18.             print("Position already taken. ")
  19.         else:
  20.             return int(position)
  21.  
  22. def main():
  23.     turn = "X"
  24.     board = ["0", "1", "2", "3", "4", "5","6", "7", "8","9"]
  25.     game_over = False
  26.     printboard(board)
  27.     while not game_over:
  28.         pos = get_input(turn, board)
  29.  
  30.  
  31.  
  32. main()
Add Comment
Please, Sign In to add comment