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)
Share:
18,127
susil95
Author by

susil95

Updated on June 05, 2022

Comments

  • susil95
    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 and j in maze so that to retain the current position and return the same to main function?

    Please tell if I'm wrong in assigning it.

  • susil95
    susil95 about 9 years
    Thanks that was very helpful.