Skip to content

Instantly share code, notes, and snippets.

@gauravpatt92
Created May 7, 2017 01:21
Show Gist options
  • Save gauravpatt92/89f23c4fe182b1638bae9b620be9e427 to your computer and use it in GitHub Desktop.
Save gauravpatt92/89f23c4fe182b1638bae9b620be9e427 to your computer and use it in GitHub Desktop.
Tic Tac Toe board entry
print ("TIC TAC TOE board. Rows and Columns starting from 1,1. Chances over after every place filled and not when someone wins.")
print ("Game board is printed after each chance to show progress!")
def print_game(game):
print ("\n")
for i in range(3):
print (str(game[i]) + "\n")
game=[[0,0,0], [0,0,0], [0,0,0]]
print_game(game)
count = 0
chance = True
while chance:
spot = input("Enter the row,column in same format as given: ")
spot = spot.split(",") #gives strings
row = int(spot[0]) -1
column = int(spot[1]) -1
if count%2==0:
print ("\nPlayer 1 chance!")
if game[row][column]==0:
game[row][column] = 'x'
else:
print ("Try Again!")
count-=1
print_game(game)
else:
print ("\nPlayer 2 chance!")
if game[row][column]==0:
game[row][column]='O'
else:
print ("Try Again!")
count-=1
print_game(game)
count+=1
if 0 in game[0] or 0 in game[1] or 0 in game[2]:
chance = True
else:
chance = False
print ("Chances Over!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment