# why is it not putting x or o instead of the space

answered Mar 8 by (140 points)
answered Mar 9 by (55,660 points)

# More work needs to be done

There are quite a number of mistakes in your code. Let me point out a few and you can work on the rest to make your game work.

# Use The Right Types

```x_move=input ("it is x's turn where would you like to go (1-9): ")
if (x_move==1):
board=x
```

The 1st line above takes an input and stores it in x_move. input() returns a type of string, so x_move is a string.

The 2nd line checks if x_move is 1. That is, it compares the variable x_move that is a string to the number 1. This comparison will not succeed. You should compare numbers to numbers. You can easily achieve this by casting the result of input() to an integral number (int).

The 3rd line tries to set an element in a list to x. However, x is not a known variable so the code will stop executing that line. What you should do here is to set the element of the list to the character x, which is denoted by 'x'.

To fix all the above 3 lines you should write something like this:

x_move=(int)(input("it is x's turn where would you like to go (1-9): "))
if (x_move==1):
board='x'

# Use The Right Variables

Consider this piece of code of yours:

```o_move=input ("it is o's turn where would you like to go (1-9): ")
if (x_move==1):
board=o```

Apart from what I've explained in the previous section ("Use The Right Types") notice that when you think the user entered 1, you try to put the o marker in its place. However, you do not compare the value the user just entered (o_move), but the previous value (x_move) incorrectly.

# Confusing Condition In While

Let's look at the below piece of code of yours (broken into multiple lines to make it more readable:

```while (not board or
" "==board or " "==board or
" " and
not board==board==board and
not board==board==board and
not board==board==board and
not board==board==board):```

I think what you're trying to do in the last 4 lines is to check horizontal and diagonal matches. However, there are 3 horizontal lines to check and you only check 2. What about the vertical lines?

I am not sure what you tried to achieve with the first line. board is a character. A character cast into a boolean (as only logical expressions can for a condition) is always true. Hence the first line is always false (not board) and since its value cannot change it doesn't serve any purpose.

The second line is checking if positions (from the user's point of view) 2 and 3 have not been set. Why is this information relevant?

The third line is a string. A string is always true as long as it's not empty. Another expression that does not change its value so it's pointless to add it to the condition.

What you should do here is this:

1. Check if there are any steps left to take (either count the steps or check if the board has empty cells)
2. Check vertically (x3), horizontally (x3) and diagonally (x2) if there are any matches

And that's it. If either of the above is true, it's game over. If both of them are false, the game keeps going.

# Mixing Data And View

It is generally a good idea to separate your data from your view. Right now, your data (board) is the view as well. It would make sense to have a board for a 3x3 matrix dedicated for ' ', 'o' and 'x' only, and a separate function for printing the board to the user with all the vertical and horizontal separators.

Good luck!

commented Mar 9 by (1,310 points)
wait so how do I check if they're equal and not a space