Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy won't this tic-tac-toe code execute?
    primarykey
    data
    text
    <p>I'm trying to learn python and have been writing a (very) simple tic-tac-toe program. However, I've got stuck because it won't seem to execute beyond letting the user enter a number. After that, nothing happens. I can't figure out where I have gone wrong. Sure there are tons of errors, but help much appreciated!</p> <p>Thanks!</p> <pre><code>import random board = range(0,9) def print_board(): print board[0], "|", board[1], "|", board[2] print board[3], "|", board[4], "|", board[5] print board[6], "|", board[7], "|", board[8] def checkAll(): if board[0] == board[1] == board[2]: True if board[3] == board[4] == board[5]: True if board[6] == board[7] == board[8]: True if board[0] == board[3] == board[6]: True if board[1] == board[4] == board[7]: True if board[2] == board[5] == board[8]: True if board[0] == board[4] == board[8]: True if board[6] == board[4] == board[2]: True print_board() while True: input = int(raw_input("Choose a number to place your X: ")) if input &lt;= 8: if board[input] != "x" or board[input] != "o": board[input] = "x" # places x if board[input] is neither x or o # Check for winner if checkAll() == True: "The game is over!" break; finding = True while finding: random.seed() # gives a random generator opponent = random.randrange(0,8) # generates a random integer between 1 and 8 if board[opponent] != "x" or board[opponent] != "o": board[opponent] = "o" # Check for winner if checkAll() == True: "The game is over!" break; else: print "This spot is taken." print_board() else: "Please choose a number between O and 8." </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload