lahabrick.blogg.se

My monitor looks like tic tac toe board
My monitor looks like tic tac toe board













' ' in board has a value of True if any of the items in board are a space, or False if there is no item with a value of space in board. Python's in operator tells you if a value is contained within a list (or certain other types). Hence no need for that.īut there's an even quicker way to do it: if ' ' in board: And then you'd need to use the key to access the value at that position in the dictionary. The source of your confusion probably comes from the fact that, when iterating over a python dict using a for loop, the variable (in this case y) would in fact be the dictionary key. When iterating over a list, the value of y is not the index of the the item in your board list, it is the value of each item. The misunderstanding is in your for loop.

my monitor looks like tic tac toe board

It's even easier than what you are doing. I just want to know what the mistake I've made is so I can learn from it.) Thank you very much! (also please don't try to make it shorter or run faster. Also take note I'm only in comp prog 1 and am at a very basic level, so simplicity would be best. If anyone knows how to get this to work the way I want that would be great. I thought this would work but I get TypeError: list indices must be integers or slices, not str refering to my if board = ' ': line. 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.) 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. """Returns a boolean value reporting the state of the board, full or not.

my monitor looks like tic tac toe board my monitor looks like tic tac toe board

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 monitor looks like tic tac toe board