"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

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -