I'm trying to build a tic tac toe game and I'm having trouble with making a working function to check if the board is full. my list for the board is
board = [' ',' ',' ',' ',' ',' ',' ',' ',' ']
and my function is
def fullBoard():
"""Returns a boolean value reporting the state of the board, full or not.
True for full, False for not full."""
for y in board:
if board[y] == ' ':
return False
print(False)
break
else:
print(True)
return True
what I want it to do is search each item in the list and when it finds a ' ' or space, it returns false and breaks the loop. but if there is no ' ' it returns true meaning the board is full (I put the print functions in just for my sake while I was trying to fix the darn thing.)
I thought this would work but I get TypeError: list indices must be integers or slices, not str refering to my if board[y] == ' ':
line. If anyone knows how to get this to work the way I want that would be great. Also take note I'm only in comp prog 1 and am at a very basic level, so simplicity would be best. (also please don't try to make it shorter or run faster. I just want to know what the mistake I've made is so I can learn from it.) Thank you very much!