At the beginning it is worth noting that I am a beginner with Python.
I've got a problem with my if
statement. I'm trying to write a line which will be checking if the player chooses X or O instead of another character. So I used that line to do that:
if player_x_or_o == 'X' or 'O':
setplayermove(row_choice, col_choice)
else:
print('Invalid value, try again.')
But if someone uses, for example 'S' the program will do first if
instead of else
.
I can not understand why, any thoughts?
# functions
def game_board(X_or_O=0, row=0, column=0, show_gb=False):
print(' 1 2 3')
if not show_gb:
game[row][column] = X_or_O
for index, listof0 in enumerate(game):
index += 1
print(index,'.',listof0)
def setplayermove(row, col):
game[row_choice][col_choice] = player_x_or_o
# Game board
game = [[0,0,0],
[0,0,0],
[0,0,0]]
game_board(show_gb=False)
# User input
while True:
player_x_or_o = str(input('Do you want put "X" or "O"? \n'))
row_choice = int(input('In which row do you want set your {}? \n'.format(player_x_or_o)))
col_choice = int(input('In which column do you want set your {}? \n'.format(player_x_or_o)))
row_choice -= 1
col_choice -= 1
if player_x_or_o == 'X' or 'O':
setplayermove(row_choice, col_choice)
else:
print('Invalid value, try again.')
game_board(show_gb=True)