def displayBoard(board): #prints the board x = 1 for y in board: if y == "_": print (x,"|", end="") else: print ("X |", end="") if x % 3 == 0: print() else: print(end=" ") x+=1 def filled(board): #returns True if there aren't any spaces open with "_" for y in board: if (y == "_"): return False return True def main(): #This is where everything starts x = "" board = ["_","_","_","_","_","_","_","_","_"] displayBoard() while filled(board) == False: print("Enter move for x (1-9):",end =" ") x = str(input()) print(x) if x == "1": board[0] = x displayBoard(board) elif x == "2": board[1] = x displayBoard(board) elif x == "3": board[2] = x displayBoard(board) elif x == "4": board[3] = x displayBoard(board) elif x == "5": board[4] = x displayBoard(board) elif x == "6": board[5] = x displayBoard(board) elif x == "7": board[6] = x displayBoard(board) elif x == "8": board[7] = x displayBoard(board) elif x == "9": board[8] = x displayBoard(board) else: print("Please enter a valid position number 1-9") if __name__ == "__main__": main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question