Passing a multidimensional array to a function in python
18,127
The maze and the position are two different objects, you cannot mix them in a way you tried. Keep them separate:
def move_mouse(m, maze, pos):
if m == 'down':
# check the maze
pos = pos[0], pos[1] + 1
return pos
maze = [[0 for x in range(8)] for x in range(8)]
pos = (4,4)
pos = move_mouse('down', maze, pos)
Author by
susil95
Updated on June 05, 2022Comments
-
susil95 almost 2 years
I was just trying an maze-mouse game, to retain the position of the mouse in array,
I created a multidimensional array in python
maze = [[0 for x in range(8)] for x in range(8)]
and I called a function using
l = move_mouse(m,maze)
function is
def move_mouse(m,maze =[i][j]): if m=='down': i = i+1 return maze
How to pass the array with with values
i
andj
inmaze
so that to retain the current position and return the same to main function?Please tell if I'm wrong in assigning it.
-
susil95 about 9 yearsThanks that was very helpful.