"Cast" to int in Python 3.4 -
i writing simple game in python 3.4. totally new in python. code below:
def shapeat(self, x, y): return self.board[(y * board.boardwidth) + x]
throws error:
typeerror: list indices must integers, not float
for have found may happen when python "thinks" list argument not integer. have idea how fix that?
int((y * board.boardwidth) + x)
use int
nearest integer towards zero.
def shapeat(self, x, y): return self.board[int((y * board.boardwidth) + x)] # give floor value.
and floor value use math.floor
(by of m.wasowski)
math.floor((y * board.boardwidth) + x)
Comments
Post a Comment