Skip to content

Instantly share code, notes, and snippets.

@mohammedvaghjipurwala
Created August 31, 2016 10:14
Show Gist options
  • Select an option

  • Save mohammedvaghjipurwala/9cdeb7ae6165de91b6acced63e166b4f to your computer and use it in GitHub Desktop.

Select an option

Save mohammedvaghjipurwala/9cdeb7ae6165de91b6acced63e166b4f to your computer and use it in GitHub Desktop.

Revisions

  1. mohammedvaghjipurwala renamed this gist Aug 31, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. mohammedvaghjipurwala created this gist Aug 31, 2016.
    34 changes: 34 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    game = [[0, 0, 0],
    [0, 0, 0],
    [0, 0, 0]]

    i = 1
    #### Prints the list in matrix form

    def PrintMat(game):
    return ('\n'.join(str(i) for i in game))

    #### to get the input from the user.

    def TicTacToeInput(game,i):
    if any(0 in s for s in game):
    if i % 2 != 0:
    Player = "X"
    else:
    Player = "O"

    print ("\nPlayer ",Player," Turn!!! \n")
    row = int(input("Enter the row (1-3): ")) - 1
    col = int(input("Enter the column (1-3): ")) - 1
    if game[row][col] == 0:
    game[row][col] = Player
    i += 1
    print (PrintMat(game))
    TicTacToeInput(game,i)
    else:
    print ("Invalid position please Try again")
    TicTacToeInput(game,i)

    if __name__ == "__main__":
    print ("Welcome to the Tic Tac Toe game !!!")
    TicTacToeInput(game,i)