I am having a problem with my try and except in python, so basically everytime a person types a letter the whole program will crash and I can not find a way to fix this error using try and except. TypeError: list indices must be integers or slices, not str
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
def add(user_A, user_B): if board[user_A] = = 0 : board[ 0 ] = 'X' elif board[user_B] = = 0 : board[ 0 ] = "O" else : print ( "Retry.." ) def game(): user_A = "" user_B = "" game = False while game ! = True : try : show() user_A = int ( input ( "\n'X' it is your turn: " )) game = True except Exception as e: time.sleep( 1 ) print (e) add(user_A, user_B) |