<reponame>aishwaryashand/Project1<gh_stars>0
#!usr/bin/python3

board=[" " for i in range(9)]
def print_board():
 row1="|{}|{}|{}|".format(board[0],board[1],board[2])
 row2="|{}|{}|{}|".format(board[3],board[4],board[5])
 row3="|{}|{}|{}|".format(board[6],board[7],board[8])
 print("")
 print(row1)
 print(row2)
 print(row3)
 print("")


def player_move(icon):
 if icon=="X":
  number=1
 elif icon=="O":
  number=2

 print("your turn player {}".format(number))
 while True:
  choice=int(input("Enter your move 1-9: "))
  if choice>0 and choice<=9:
   if board[choice-1]==" ":
    board[choice-1]=icon
    break
   elif board[choice-1]=="X" or board[choice-1]=="O":
    print("")
    print("Sorry! That space is taken.")
    continue
  else:
   print("")
   print("Enter a valid input")
   continue


def is_victory(icon):
 if(board[0]==icon and board[1]==icon and board[2]==icon) or \
   (board[3]==icon and board[4]==icon and board[5]==icon) or \
   (board[6]==icon and board[7]==icon and board[8]==icon) or \
   (board[0]==icon and board[3]==icon and board[6]==icon) or \
   (board[1]==icon and board[4]==icon and board[7]==icon) or \
   (board[2]==icon and board[5]==icon and board[8]==icon) or \
   (board[0]==icon and board[4]==icon and board[8]==icon) or \
   (board[2]==icon and board[4]==icon and board[6]==icon):
    return True
 else:
    return False


def is_draw():
 if " " not in board:
  return True
 else:
  return False

print_board()

while True: 
 player_move("X") 
 print_board()
 if is_victory("X"):
  print("Player 1 wins!")
  break
 elif is_draw():
  print("Oops! Its a draw.")
  break

 player_move("O")
 if is_victory("O"):
  print("Player 2 wins!")
  break
 elif is_draw():
  print("Oops! Its a draw.")
  break
 print_board()

#!usr/bin/python3

board=[" " for i in range(9)]
def print_board():
 row1="|{}|{}|{}|".format(board[0],board[1],board[2])
 row2="|{}|{}|{}|".format(board[3],board[4],board[5])
 row3="|{}|{}|{}|".format(board[6],board[7],board[8])
 print("")
 print(row1)
 print(row2)
 print(row3)
 print("")


def player_move(icon):
 if icon=="X":
  number=1
 elif icon=="O":
  number=2

 print("your turn player {}".format(number))
 while True:
  choice=int(input("Enter your move 1-9: "))
  if choice>0 and choice<=9:
   if board[choice-1]==" ":
    board[choice-1]=icon
    break
   elif board[choice-1]=="X" or board[choice-1]=="O":
    print("")
    print("Sorry! That space is taken.")
    continue
  else:
   print("")
   print("Enter a valid input")
   continue


def is_victory(icon):
 if(board[0]==icon and board[1]==icon and board[2]==icon) or \
   (board[3]==icon and board[4]==icon and board[5]==icon) or \
   (board[6]==icon and board[7]==icon and board[8]==icon) or \
   (board[0]==icon and board[3]==icon and board[6]==icon) or \
   (board[1]==icon and board[4]==icon and board[7]==icon) or \
   (board[2]==icon and board[5]==icon and board[8]==icon) or \
   (board[0]==icon and board[4]==icon and board[8]==icon) or \
   (board[2]==icon and board[4]==icon and board[6]==icon):
    return True
 else:
    return False


def is_draw():
 if " " not in board:
  return True
 else:
  return False

print_board()

while True: 
 player_move("X") 
 print_board()
 if is_victory("X"):
  print("Player 1 wins!")
  break
 elif is_draw():
  print("Oops! Its a draw.")
  break

 player_move("O")
 if is_victory("O"):
  print("Player 2 wins!")
  break
 elif is_draw():
  print("Oops! Its a draw.")
  break
 print_board()
#!usr/bin/python3