[Tutor] Bug
Cameron Simpson
cs at zip.com.au
Wed May 17 18:00:22 EDT 2017
On 17May2017 12:26, Grace Sanford <gsanford at wesleyan.edu> wrote:
>Theoretically, the following code is suppose to check if the user has won a
>tic tac toe game by checking if there are all "X"s in either the
>horizontal, vertical, or diagonal lines of a grid (represented by a list
>with "board" with elements 0-8). If one of these is the case, it is
>suppose to print the "You won" string. Nevertheless, when I change list
>variable to reflect one of these conditions, there is no printing
>occurring. I cannot figure out why.
>
>if board[0:3]==["X", "X", "X"] or board[3:6]==["X", "X", "X"] or
>board[6:9]==["X", "X", "X"] or \
> [board[0],board[3],board[6]]==["X", "X", "X"] or
>[board[1],board[4],board[7]]==["X", "X", "X"] or
>[board[2],board[5],board[8]] ==["X", "X", "X"] or \
> [board[0],board[4],board[8]]==["X", "X", "X"] or
>[board[2],board[4],board[6]]==["X", "X", "X"]:
Please post complete code, and the output (I accept that in your case the
output is empty). For example:
board = [ "X", "X", "X",
"", "", "",
"", "", ""
]
if board[0:3]==["X", "X", "X"] or board[3:6]==["X", "X", "X"] or board[6:9]==["X", "X", "X"] or \
[board[0],board[3],board[6]]==["X", "X", "X"] or [board[1],board[4],board[7]]==["X", "X", "X"] or [board[2],board[5],board[8]] ==["X", "X", "X"] or \
[board[0],board[4],board[8]]==["X", "X", "X"] or [board[2],board[4],board[6]]==["X", "X", "X"]:
print("ROW!")
so that proeple can reproduce your problem. For example, it may be that some
winning positions do work and some don't, and you've tested only a failing
combination.
The example I have above prints "ROW!" for me, and it is just your own code
with a specific combination.
Cheers,
Cameron Simpson <cs at zip.com.au>
More information about the Tutor
mailing list