Sep-22-2020, 04:40 PM
Hey, Im trying to get this function to return a value like [x][y]
but it keeps giving me "line 54, in move
return [new_row][new_col]
IndexError: list index out of range."
(sorry for not knowing the correct terms for some of this stuff, im just starting out.)
is there any way to get it to return [x][y] without the index error? Thanks.
but it keeps giving me "line 54, in move
return [new_row][new_col]
IndexError: list index out of range."
(sorry for not knowing the correct terms for some of this stuff, im just starting out.)
player_row = 0 player_col = 0 def move(direction): new_col = player_col new_row = player_row if direction == "up": new_col += -1 elif direction == "down": new_col += 1 if direction == "left": new_row += -1 elif direction == "right": new_row += 1 return [new_row][new_col] print(move("down"))It gives me a [x] value if i remove either new_row or new_col from the return,
player_row = 0 player_col = 0 def move(direction): new_col = player_col new_row = player_row if direction == "up": new_col += -1 elif direction == "down": new_col += 1 if direction == "left": new_row += -1 elif direction == "right": new_row += 1 return [new_col] print(move("down"))and it will give me ([x],[y]) if i return "return [new_row], [new_col].
is there any way to get it to return [x][y] without the index error? Thanks.