Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tic tac toe loop
#1
Exclamation 
I've been having troubles with getting a loop for tic tac toe
here is the code
board = [1, 2, 3, 4, 5, 6, 7, 8, 9]
print("Welcome to Tic-Tac-Toe!")
print(" " + str(board[0]) + " | " + str(board[1]) + " | " + str(board[2]) + " ")
print("-----------")
print(" " + str(board[3]) + " | " + str(board[4]) + " | " + str(board[5]) + " ")
print("-----------")
print(" " + str(board[6]) + " | " + str(board[7]) + " | " + str(board[8]) + " ")

board_location = input("Enter the board location to play for player X: ")
board_location = int(board_location)
board_index = board_location - 1
board[board_index] = "X"
print(" " + str(board[0]) + " | " + str(board[1]) + " | " + str(board[2]) + " ")
print("-----------")
print(" " + str(board[3]) + " | " + str(board[4]) + " | " + str(board[5]) + " ")
print("-----------")
print(" " + str(board[6]) + " | " + str(board[7]) + " | " + str(board[8]) + " ")

board_location = input("Enter the board location to play for player O: ")
board_location = int(board_location)
board_index = board_location - 1
board[board_index] = "O"
print(" " + str(board[0]) + " | " + str(board[1]) + " | " + str(board[2]) + " ")
print("-----------")
print(" " + str(board[3]) + " | " + str(board[4]) + " | " + str(board[5]) + " ")
print("-----------")
print(" " + str(board[6]) + " | " + str(board[7]) + " | " + str(board[8]) + " ")
Reply


Messages In This Thread
tic tac toe loop - by ilikedofs - May-23-2021, 05:00 PM
RE: tic tac toe loop - by Yoriz - May-23-2021, 05:55 PM
RE: tic tac toe loop - by jefsummers - May-24-2021, 11:19 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020