Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

is there an easier way to see if someone has won

+2 votes
asked Feb 23 by Sam (1,310 points)

2 Answers

+1 vote
answered Feb 24 by Peter Minarik (55,660 points)
You shared a code that does not (even compile neither) have any existing check for winning or losing, so the "easier way" doesn't really apply as there's nothing to compare to. :)

To check if someone is a winner, you should check horizontal, vertical and diagonal lines for the same symbol ('x' or 'o').

I'd have a two-dimensional 3x3 array to store the board with 3 possible values: 'x', 'o' and nothing entered yet, e.g. ' ' (space).

Then you check if every symbol is the same (horizontally, vertically or diagonally).

Does this make sense?
0 votes
answered Apr 2 by userdotexe (1,330 points)
edited Apr 2 by userdotexe

You might find these articles helpful:

Edit: Also there is an error in your code:
board='''
        |     |
        |     |
--------|-----|--------
        |     |
        |     |
--------|-----|--------
        |     |
        |     |
'''
print (board)
while (board!=)
    x_move=input ("it is x's turn where would you like to go (1-9): ")
    print (board)
    o_move=input ("it is o's turn where would you like to go (1-9): ")
    print (board)
You can't do while (board!=), without telling what the board must not be equal to, i.e.:
board='''
        |     |
        |     |
--------|-----|--------
        |     |
        |     |
--------|-----|--------
        |     |
        |     |
'''
print (board)
while (board!=what the board must not be equal to)
    x_move=input ("it is x's turn where would you like to go (1-9): ")
    print (board)
    o_move=input ("it is o's turn where would you like to go (1-9): ")
    print (board)
:)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...